コード例 #1
0
def generate_dataset(n_measures,
                     tempo=Tempo(120),
                     scale=GenericScale('C', [0, 2, 3, 5, 7, 8, 10]),
                     sampling_info=SamplingInfo(44100)):

    signature = Signature(4, 4)
    n_notes_per_measure = 4

    bass_instrument = make_bass_instrument(sampling_info)
    lead_instrument = make_lead_instrument(sampling_info)
    chord_instrument = make_accomp_instrument(sampling_info)

    chord_track = generate_chord_track(scale, tempo, signature, n_measures)
    y_chord = chord_instrument.generate_track(chord_track)

    lead_track = generate_lead_track(scale, tempo, signature, n_measures,
                                     n_notes_per_measure)
    y_lead = lead_instrument.generate_track(lead_track)

    bass_track = generate_bass_track(scale, tempo, signature, n_measures)
    y_bass = bass_instrument.generate_track(bass_track)

    mix = mixdown([y_bass, y_chord, y_lead])

    return [bass_track, chord_track, lead_track], [y_bass, y_chord,
                                                   y_lead], mix
コード例 #2
0
def test_chords_scale():
    major_scale = GenericScale('C', [0, 2, 4, 5, 7, 9, 11])

    csd = ChordInScaleDefinition(major_scale)
    csd.generate_chord(Note('C', 3))

    assert True
コード例 #3
0
    def is_in_scale(self, scale: GenericScale):
        symbols_in_chord = self.get_symbols()
        symbols_in_scale = scale.get_symbols()

        if set(symbols_in_chord) - set(symbols_in_scale) == set():
            return True
        else:
            return False
コード例 #4
0
def lead():
    lead = generate_dataset(n_measures=4,
                            tempo=Tempo(120),
                            scale=GenericScale('C', [0, 2, 3, 5, 7, 8, 10]),
                            sampling_info=SamplingInfo(44100))[1][2]

    lead = np.concatenate((lead, np.zeros(shape=44100)), axis=0)
    return lead
コード例 #5
0
def test_in_scale():
    major_scale = GenericScale('C', [0, 2, 4, 5, 7, 9, 11])

    major_chord = MajorChordDefinition()
    chord = major_chord.generate_chord(Note('C', 3))
    assert chord.is_in_scale(major_scale)

    major_chord = MajorChordDefinition()
    chord = major_chord.generate_chord(Note('D', 3))
    assert not chord.is_in_scale(major_scale)
コード例 #6
0
def main(length, note_duration):
    """Main function

    Args:
        length (float): length in seconds
        note_duration (float): duration of a single notes in seconds

    Returns:
        int: program exit-code
    """

    sampling_info = SamplingInfo(88200)

    score_tracks, audio_tracks, mix = generate_dataset(
        n_measures=16,
        tempo=Tempo(100),
        scale=GenericScale('E', [0, 2, 3, 5, 7, 8, 10]),
        sampling_info=sampling_info)

    play_array(mix, sampling_info.sample_rate)

    return 0
コード例 #7
0
def generate_dataset_for_root(root):
    return generate_dataset(n_measures=32,
                            tempo=Tempo(120),
                            scale=GenericScale(root, [0, 2, 3, 5, 7, 8, 10]),
                            sampling_info=sampling_info)