Exemplo n.º 1
0
def vader_jacob():

    theme1 = Measure(Tempo(120), Signature(4, 4)) \
        .add_note(Note('C', 3), 0, 1) \
        .add_note(Note('D', 3), 1, 1) \
        .add_note(Note('E', 3), 2, 1) \
        .add_note(Note('C', 3), 3, 1)

    theme2 = Measure(Tempo(120), Signature(4, 4)) \
        .add_note(Note('E', 3), 0, 1) \
        .add_note(Note('F', 3), 1, 1) \
        .add_note(Note('G', 3), 2, 2)

    theme3 = Measure(Tempo(120), Signature(4, 4)) \
        .add_note(Note('G', 3), 0, 0.5) \
        .add_note(Note('A', 3), 0.5, 0.5) \
        .add_note(Note('G', 3), 1, 0.5) \
        .add_note(Note('F', 3), 1.5, 0.5) \
        .add_note(Note('E', 3), 2, 1) \
        .add_note(Note('C', 3), 3, 1)

    theme4 = Measure(Tempo(120), Signature(4, 4)) \
        .add_note(Note('C', 3), 0, 1) \
        .add_note(Note('G', 2), 1, 1) \
        .add_note(Note('C', 3), 2, 2)

    track = Track([theme1] * 2 + [theme2] * 2 + [theme3] * 2 + [theme4] * 2)

    return track
Exemplo n.º 2
0
def test_duration():
    duration = Duration.from_num_beats(2, Tempo(120))
    assert duration.seconds == 1

    tempo = Tempo(613)
    duration = Duration.from_num_beats(0.5, tempo)
    assert duration.beats(tempo) == 0.5

    assert Duration.from_num_beats(1, Tempo(120)).samples(44100) == 22050
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
Exemplo n.º 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
Exemplo n.º 5
0
def test_measure_note_generate():
    measure = Measure(Tempo(120), Signature(4, 4))
    measure.add_note(Note('C#', 3), 0, 1)
    measure.add_note(Note('D', 3), 1, 1)
    measure.add_note(Note('E', 3), 2, 1)
    measure.add_note(Note('C#', 3), 3, 1)
    result = measure.generate_notes(Duration(1.5))
    assert result[0].offset.seconds == (measure.notes[0].offset +
                                        Duration(1.5)).seconds
    pass
Exemplo n.º 6
0
def test_measure():

    measure = Measure(Tempo(120), Signature(4, 4))

    measure.add_note(Note('C', 3), 0, 1)
    measure.add_note(Note('D', 3), 1, 1)
    measure.add_note(Note('E', 3), 2, 1)
    measure.add_note(Note('C', 3), 3, 1)

    assert len(measure.notes) == 4
def test_max_duration():
    measure = Measure(Tempo(120), Signature(4, 4))
    measure.add_note(Note('C#', 3), 0, 1)
    measure.add_note(Note('F', 3), 2, 5)
    measure.add_note(Note('D', 3), 1, 1)
    measure.add_note(Note('E', 3), 2, 1)
    measure.add_note(Note('C#', 3), 3, 1)

    max_duration = get_max_duration(measure.generate_notes(Duration(1.5)))

    assert max_duration.seconds == 5.0
Exemplo n.º 8
0
    def generate_chord(self, chord: Chord, time: Duration):

        tempo = Tempo(120)
        measure = Measure(tempo, Signature(4, 4))

        for n in chord.notes:
            measure.add_note(n, 0, duration=time.beats(tempo))

        track = Track([measure])

        return self.generate_track(track)
Exemplo n.º 9
0
def test_duration_operators():
    duration = Duration.from_num_beats(2, Tempo(120))
    assert duration.seconds == 1

    assert (duration * 2).seconds == 2
    assert duration.seconds == 1

    assert (2 * duration).seconds == 2
    assert duration.seconds == 1

    assert (duration + Duration(1)).seconds == 2
    assert duration.seconds == 1

    pass
Exemplo n.º 10
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
Exemplo n.º 11
0
def test_bar():
    bar = Measure(Tempo(120), Signature(3, 4))
    assert bar.total_time().seconds == 1.5
Exemplo n.º 12
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)
Exemplo n.º 13
0
def test_tempo():
    tempo = Tempo(120)
    assert tempo.quarter_note().seconds == 0.5