コード例 #1
0
    def convert_line(line,
                     tempo=Tempo(60, Duration(1, 4)),
                     time_signature=TimeSignature(4, Duration(1, 4)),
                     channel_assignments=None,
                     fps=42100):
        """
        Static method to convert a Line to a midi file

        Args:
          :param line: Class Line object
          :param tempo: Tempo for playback, default is 60 BPM tempo beat = quarter note
          :param time_signature: TimeSiganture on playback, default is 4 quarter notes
          :param channel_assignments:
          :param fps: frames per second setting

        """
        score = Score()
        tempo_sequence = score.tempo_sequence
        tempo_sequence.add(TempoEvent(tempo, Position(0)))

        ts_sequence = score.time_signature_sequence
        ts_sequence.add(TimeSignatureEvent(time_signature, Position(0)))

        c = InstrumentCatalog.instance()
        piano = c.get_instrument("piano")

        piano_instrument_voice = InstrumentVoice(piano, 1)
        piano_voice = piano_instrument_voice.voice(0)

        piano_voice.pin(line, Offset(0))

        score.add_instrument_voice(piano_instrument_voice)
        return ScoreToVstMidiConverter.convert_score(score,
                                                     channel_assignments, fps)
コード例 #2
0
    def test_basic_setup(self):
        c = InstrumentCatalog.instance()

        score = Score()

        violin = c.get_instrument("violin")
        violin_instrument_voice = InstrumentVoice(violin, 5)
        score.add_instrument_voice(violin_instrument_voice)

        trumpet = c.get_instrument("trumpet")
        trumpet_instrument_voice = InstrumentVoice(trumpet)
        score.add_instrument_voice(trumpet_instrument_voice)

        clarinet = c.get_instrument("clarinet")
        clarinet_instrument_voice = InstrumentVoice(clarinet)
        score.add_instrument_voice(clarinet_instrument_voice)

        voices = score.instrument_voices
        assert len(voices) == 3

        classes = score.instrument_classes
        assert len(classes) == 3

        assert TestScore.has_class(classes, 'strings')
        assert TestScore.has_class(classes, 'woodwinds')
        assert TestScore.has_class(classes, 'brass')

        score.remove_instrument_voice(trumpet_instrument_voice)
        classes = score.instrument_classes
        assert len(classes) == 2
        assert TestScore.has_class(classes, 'strings')
        assert TestScore.has_class(classes, 'woodwinds')
コード例 #3
0
    def test_book_example(self):

        score = Score()

        # set up 3 instrument voices: 2 violins, 1 trumpet, 1 clarinet
        catalogue = InstrumentCatalog.instance()
        score.add_instrument_voice(
            InstrumentVoice(catalogue.get_instrument("violin"), 2))
        score.add_instrument_voice(
            InstrumentVoice(catalogue.get_instrument("trumpet")))
        score.add_instrument_voice(
            InstrumentVoice(catalogue.get_instrument("clarinet")))

        #  1 beat == 1 sec, 3/4 TS + 60 beats per minute,
        score.tempo_sequence.add(TempoEvent(Tempo(60), Position(0)))
        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))

        # set up some notes in the two violins
        violin_voice = score.get_instrument_voice("violin")[0]
        violin_voice.voice(0).pin(
            Line([Note(DiatonicPitch(4, y), Duration(1, 8))
                  for y in 'afdecd']))
        violin_voice.voice(0).pin(
            Line([Note(DiatonicPitch(4, y), Duration(1, 4)) for y in 'cdc']))
コード例 #4
0
    def test_tempo_change(self):
        c = InstrumentCatalog.instance()

        score = Score()

        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(120, Duration(1, 4)), Position(0)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(60, Duration(1, 4)), Position(1)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(30, Duration(1, 4)), Position(2)))

        violin = c.get_instrument("violin")
        violin_instrument_voice = InstrumentVoice(violin, 1)
        violin_voice_0 = violin_instrument_voice.voice(0)
        assert violin_voice_0
        score.add_instrument_voice(violin_instrument_voice)

        violin_voice_0.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.F), Position(0)))

        # Add notes to the score
        vnote0 = Note(DiatonicPitch(4, 'a'), Duration(1, 4))
        vnote1 = Note(DiatonicPitch(4, 'b'), Duration(1, 4))
        vnote2 = Note(DiatonicPitch(5, 'c'), Duration(1, 4))
        vnote3 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))

        vnote4 = Note(DiatonicPitch(4, 'a'), Duration(1, 4))
        vnote5 = Note(DiatonicPitch(4, 'b'), Duration(1, 4))
        vnote6 = Note(DiatonicPitch(5, 'c'), Duration(1, 4))
        vnote7 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))

        vnote8 = Note(DiatonicPitch(4, 'a'), Duration(1, 4))
        vnote9 = Note(DiatonicPitch(4, 'b'), Duration(1, 4))
        vnote10 = Note(DiatonicPitch(5, 'c'), Duration(1, 4))
        vnote11 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))

        # Set up a violin voice with 6 8th notes
        vline_0 = Line([
            vnote0, vnote1, vnote2, vnote3, vnote4, vnote5, vnote6, vnote7,
            vnote8, vnote9, vnote10, vnote11
        ])
        violin_voice_0.pin(vline_0)

        # Set up a violin voice with 6 8th notes
        vline_1 = Line([vnote0, vnote1, vnote2, vnote3])
        violin_voice_0.pin(vline_1)

        smc = ScoreToMidiConverter(score)
        smc.create('score_tempo_change_file.mid')

        TestScoreToMidiConverter.read_midi_file('score_tempo_change_file.mid')
コード例 #5
0
    def test_adding_notes(self):
        score = Score()

        # set up 3 instrument voices: 2 violins, 1 trumpet, 1 clarinet
        catalogue = InstrumentCatalog.instance()
        score.add_instrument_voice(
            InstrumentVoice(catalogue.get_instrument("violin"), 2))

        #  1 beat == 1 sec, 3/4 TS + 60 beats per minute,
        score.tempo_sequence.add(TempoEvent(Tempo(60), Position(0)))
        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))

        violin_voice = score.get_instrument_voice("violin")[0]

        line = Line([Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'afd'])
        violin_voice.voice(0).pin(line)

        notes = violin_voice.get_all_notes()
        for n in notes:
            print(n)

        line.append(Note(DiatonicPitch(4, 'g'), Duration(1, 8)))
        notes = violin_voice.get_all_notes()
        for n in notes:
            print(n)
コード例 #6
0
    def test_score_book_example(self):
        score = Score()

        catalogue = InstrumentCatalog.instance()
        score.add_instrument_voice(
            InstrumentVoice(catalogue.get_instrument("violin")))

        score.tempo_sequence.add(TempoEvent(Tempo(60), Position(0)))
        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(4, Duration(1, 4)), Position(0)))

        violin_voice = score.get_instrument_voice("violin")[0]
        note_1 = Note(DiatonicPitch(4, 'A'), Duration(1, 4))
        note_2 = Note(DiatonicPitch(5, 'C'), Duration(1, 8))
        note_3 = Note(DiatonicPitch(5, 'B'), Duration(1, 8))
        note_4 = Note(DiatonicPitch(5, 'D'), Duration(1, 4))
        note_5 = Note(DiatonicPitch(5, 'E'), Duration(1, 8))
        note_6 = Note(DiatonicPitch(5, 'D'), Duration(1, 8))
        note_7 = Note(DiatonicPitch(4, 'G'), Duration(1, 4))
        note_8 = Note(DiatonicPitch(4, 'C'), Duration(1, 4))
        line = Line(
            [note_1, note_2, note_3, note_4, note_5, note_6, note_7, note_8])
        violin_voice.voice(0).pin(line)

        smc = ScoreToMidiConverter(score)
        smc.create('book_example_midi_file.mid', True)

        ScoreToMidiConverter.convert_line(line,
                                          'line_example_midi_file.mid',
                                          Tempo(90, Duration(1, 8)),
                                          instrument_name='violin')
コード例 #7
0
    def test_score_convert(self):
        c = InstrumentCatalog.instance()

        score = Score()

        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(60, Duration(1, 4)), Position(0)))

        violin = c.get_instrument("violin")
        violin_instrument_voice = InstrumentVoice(violin, 2)
        violin_voice_0 = violin_instrument_voice.voice(0)
        violin_voice_1 = violin_instrument_voice.voice(1)
        assert violin_voice_0
        assert violin_voice_1
        score.add_instrument_voice(violin_instrument_voice)

        violin_voice_0.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.P), Position(0)))
        violin_voice_0.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.FFF), Position(1, 4)))
        violin_voice_1.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.P), Position(0)))
        violin_voice_1.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.FFF), Position(1, 4)))

        # Add notes to the score
        vnote0 = Note(DiatonicPitch(4, 'a'), Duration(1, 8))
        vnote1 = Note(DiatonicPitch(4, 'b'), Duration(1, 8))
        vnote2 = Note(DiatonicPitch(5, 'c'), Duration(1, 8))
        vnote3 = Note(DiatonicPitch(4, 'd'), Duration(1, 8))
        vnote4 = Note(DiatonicPitch(4, 'e'), Duration(1, 8))
        vnote5 = Note(DiatonicPitch(4, 'f'), Duration(1, 8))

        # Set up a violin voice with 6 8th notes
        vline_0 = Line([vnote0, vnote1, vnote2])
        violin_voice_0.pin(vline_0)

        # Set up a violin voice with 6 8th notes
        vline_1 = Line([vnote3, vnote4, vnote5])
        violin_voice_1.pin(vline_1)

        smc = ScoreToMidiConverter(score)
        smc.create('score_output_file.mid')

        TestScoreToMidiConverter.read_midi_file('score_output_file.mid')
コード例 #8
0
    def test_dynamic_volume(self):
        c = InstrumentCatalog.instance()

        score = Score()

        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(60, Duration(1, 4)), Position(0)))

        violin = c.get_instrument("violin")

        note0 = Note(DiatonicPitch(4, 'a'), Duration(3, 2))
        note1 = Note(DiatonicPitch(4, 'b'), Duration(1, 2))
        note2 = Note(DiatonicPitch(5, 'c'), Duration(1, 2))
        note3 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))
        note4 = Note(DiatonicPitch(5, 'g'), Duration(1, 4))
        note5 = Note(DiatonicPitch(5, 'f'), Duration(1, 4))
        note6 = Note(DiatonicPitch(5, 'e'), Duration(1, 4))
        note7 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))

        violin_instrument_voice = InstrumentVoice(violin, 1)
        violin_voice = violin_instrument_voice.voice(0)
        assert violin_voice

        vline = Line([note0, note1, note2, note3, note4, note5, note6, note7])
        violin_voice.pin(vline)

        score.add_instrument_voice(violin_instrument_voice)

        # create a crescendo

        v_low = Dynamics.PPP.velocity
        v_hi = Dynamics.FFFF.velocity
        array = [(Position(0), v_low), (Position(3, 2), v_hi)]
        f = PiecewiseLinearFunction(array)
        event1 = DynamicsFunctionEvent(f, Position(0))

        violin_voice.dynamics_sequence.add(event1)

        smc = ScoreToMidiConverter(score)
        smc.create('score_vary_volume_file.mid')

        TestScoreToMidiConverter.read_midi_file('score_vary_volume_file.mid')
コード例 #9
0
def build_vst_midi_list():
    """

    :return:
    """
    c = InstrumentCatalog.instance()

    # Add notes to the score
    vnote0 = Note(DiatonicPitch(4, 'a'), Duration(1, 8))
    vnote1 = Note(DiatonicPitch(4, 'b'), Duration(1, 8))
    vnote2 = Note(DiatonicPitch(4, 'c'), Duration(1, 8))
    vnote3 = Note(DiatonicPitch(4, 'd'), Duration(1, 8))
    vnote4 = Note(DiatonicPitch(4, 'e'), Duration(1, 8))
    vnote5 = Note(DiatonicPitch(4, 'f'), Duration(1, 8))

    # Set up a violin voice with 6 8th notes
    vline = Line([vnote0, vnote1, vnote2, vnote3, vnote4, vnote5])

    tempo_seq = TempoEventSequence()
    ts_seq = EventSequence()
    tempo_seq.add(TempoEvent(Tempo(60), Position(0)))
    ts_seq.add(
        TimeSignatureEvent(TimeSignature(3, Duration(1, 4), 'sww'),
                           Position(0)))

    hc_track = HarmonicContextTrack()
    diatonic_tonality = Tonality.create(ModalityType.Major, DiatonicTone("C"))
    chord_t = TertianChordTemplate.parse('tIV')
    chord = chord_t.create_chord(diatonic_tonality)
    hc_track.append(HarmonicContext(diatonic_tonality, chord, Duration(2)))

    score = Score()

    score.tempo_sequence.add(TempoEvent(Tempo(60), Position(0)))
    score.time_signature_sequence.add(
        TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))

    violin = c.get_instrument("violin")
    violin_instrument_voice = InstrumentVoice(violin, 1)
    score.add_instrument_voice(violin_instrument_voice)
    violin_instrument_voice.voice(0).pin(vline)

    return ScoreToVstMidiConverter.convert_score(score, {0: 0}), score
コード例 #10
0
    def test_variable_tempo_change(self):
        c = InstrumentCatalog.instance()

        score = Score()

        violin = c.get_instrument("violin")
        violin_instrument_voice = InstrumentVoice(violin, 1)
        violin_voice = violin_instrument_voice.voice(0)
        assert violin_voice
        score.add_instrument_voice(violin_instrument_voice)

        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))

        score.tempo_sequence.add(
            TempoEvent(Tempo(60, Duration(1, 4)), Position(0)))

        t_low = 60
        t_hi = 250
        array = [(Position(0), t_low), (Position(1), t_hi),
                 (Position(2), t_hi), (Position(3), t_low)]
        f = PiecewiseLinearFunction(array)
        event1 = TempoFunctionEvent(f, Position(1))
        score.tempo_sequence.add(event1)

        score.tempo_sequence.add(
            TempoEvent(Tempo(t_low, Duration(1, 4)), Position(4)))

        # create notes
        notes = []
        for _ in range(0, 6):
            notes.append(Note(DiatonicPitch(4, 'c'), Duration(1, 4)))
            notes.append(Note(DiatonicPitch(4, 'd'), Duration(1, 4)))
            notes.append(Note(DiatonicPitch(4, 'e'), Duration(1, 4)))
            notes.append(Note(DiatonicPitch(4, 'f'), Duration(1, 4)))
        vline = Line(notes)
        violin_voice.pin(vline)

        smc = ScoreToMidiConverter(score)
        smc.create('score_var_tempo_change_file.mid')

        TestScoreToMidiConverter.read_midi_file(
            'score_var_tempo_change_file.mid')
コード例 #11
0
    def convert_line(line,
                     filename,
                     tempo=Tempo(60, Duration(1, 4)),
                     time_signature=TimeSignature(4, Duration(1, 4)),
                     instrument_name='piano'):
        """
        Static method to convert a Line to a midi file
        
        Args:
          line: Class Line object
          filename: The name of the midi file, should have filetype .mid
          tempo: Tempo for playback, default is 60 BPM tempo beat = quarter note
          time_signature: TimeSiganture on playback, default is 4 quarter notes
          instrument_name: Name of instrument ot use for playback.
        """
        score = Score()
        tempo_sequence = score.tempo_sequence
        tempo_sequence.add(TempoEvent(tempo, Position(0)))

        ts_sequence = score.time_signature_sequence
        ts_sequence.add(TimeSignatureEvent(time_signature, Position(0)))

        c = InstrumentCatalog.instance()
        instrument = c.get_instrument(instrument_name)
        if instrument is None:
            print('Error: instrument {0} cannnot be found'.format(
                instrument_name))
            return

        instrument_voice = InstrumentVoice(instrument, 1)
        piano_voice = instrument_voice.voice(0)

        piano_voice.pin(line, Offset(0))

        score.add_instrument_voice(instrument_voice)
        ScoreToMidiConverter.convert_score(score, filename)
コード例 #12
0
    def test_multi_track(self):
        c = InstrumentCatalog.instance()

        score = Score()

        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(60, Duration(1, 4)), Position(0)))

        violin = c.get_instrument("violin")
        piano = c.get_instrument("piano")

        note0 = Note(DiatonicPitch(4, 'a'), Duration(1, 4))
        note1 = Note(DiatonicPitch(4, 'b'), Duration(1, 4))
        note2 = Note(DiatonicPitch(4, 'c'), Duration(1, 4))
        note3 = Note(DiatonicPitch(4, 'd'), Duration(1, 4))
        note4 = Note(DiatonicPitch(5, 'g'), Duration(1, 4))
        note5 = Note(DiatonicPitch(5, 'f'), Duration(1, 4))
        note6 = Note(DiatonicPitch(5, 'e'), Duration(1, 4))
        note7 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))

        violin_instrument_voice = InstrumentVoice(violin, 1)
        violin_voice = violin_instrument_voice.voice(0)
        assert violin_voice

        vline = Line([note0, note1, note2, note3])
        violin_voice.pin(vline)

        score.add_instrument_voice(violin_instrument_voice)

        piano_instrument_voice = InstrumentVoice(piano, 1)
        piano_voice = piano_instrument_voice.voice(0)
        assert piano_voice

        pline = Line([note4, note5, note6, note7])
        piano_voice.pin(pline, Offset(1, 8))

        score.add_instrument_voice(piano_instrument_voice)

        violin_voice.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.F), Position(0)))
        piano_voice.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.P), Position(0)))

        smc = ScoreToMidiConverter(score)
        smc.create('score_multi_trackoutput_file.mid')

        TestScoreToMidiConverter.read_midi_file(
            'score_multi_trackoutput_file.mid')
コード例 #13
0
    def test_add_notes_to_two_level_line(self):
        score = Score()

        catalogue = InstrumentCatalog.instance()
        score.add_instrument_voice(
            InstrumentVoice(catalogue.get_instrument("violin")))

        #  1 beat == 1 sec, 3/4 TS + 60 beats per minute,
        score.tempo_sequence.add(TempoEvent(Tempo(60), Position(0)))
        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))

        violin_voice = score.get_instrument_voice("violin")[0]
        top_line = Line(
            [Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'afdecd'])
        violin_voice.voice(0).pin(top_line, Offset(0))
        level1_line = Line(
            [Note(DiatonicPitch(5, y), Duration(1, 8)) for y in 'af'])
        top_line.pin(level1_line, Offset(2))
        level2_line = Line(
            [Note(DiatonicPitch(6, y), Duration(1, 8)) for y in 'de'])
        level1_line.pin(level2_line, Offset(1))
コード例 #14
0
    def test_acquire_notes(self):
        c = InstrumentCatalog.instance()

        score = Score()

        violin = c.get_instrument("violin")
        violin_instrument_voice = InstrumentVoice(violin)
        violin_voice = violin_instrument_voice.voice(0)
        assert violin_voice
        score.add_instrument_voice(violin_instrument_voice)

        clarinet = c.get_instrument("clarinet")
        clarinet_instrument_voice = InstrumentVoice(clarinet)
        clarinet_voice = clarinet_instrument_voice.voice(0)
        assert clarinet_voice
        score.add_instrument_voice(clarinet_instrument_voice)

        # Add notes to the score
        note_list = [
            Note(DiatonicPitch(4, y), Duration(1, 8)) for y in 'abcdef'
        ]

        # Set up a violin voice with 6 8th notes
        vline = Line(note_list)
        violin_voice.pin(vline)

        cnote0 = Note(DiatonicPitch(5, 'a'), Duration(1, 4))
        cnote1 = Note(DiatonicPitch(5, 'b'), Duration(1, 4))
        cnote2 = Note(DiatonicPitch(5, 'c'), Duration(1, 4))
        cnote3 = Note(DiatonicPitch(5, 'd'), Duration(1, 4))

        # set up a clarinet line with 4 1`/4 notes
        cline = Line([cnote0, cnote1, cnote2, cnote3])
        clarinet_voice.pin(cline)

        # search for notes sounding in [1/4, 3/4)
        voice_note_map = score.get_notes_by_wnt_interval(
            Interval(Position(1, 4), Position(3, 4)))
        assert voice_note_map
        for (k, v) in voice_note_map.items():
            print('InstrumentVoice {0}:'.format(k))
            for (k1, v1) in v.items():
                print('     {0} --> [{1}]'.format(
                    k1.instrument, ', '.join(str(n) for n in v1)))

        cvoice_map = voice_note_map.get(clarinet_instrument_voice)
        cvoices = list(cvoice_map.keys())
        assert cvoice_map
        assert cvoices[0] in cvoice_map
        cnotes = cvoice_map[cvoices[0]]
        assert len(cnotes) == 2
        assert TestScore.has_pitch(cnotes, DiatonicPitch.parse('B:5'))
        assert TestScore.has_pitch(cnotes, DiatonicPitch.parse('C:5'))

        vvoice_map = voice_note_map.get(violin_instrument_voice)
        vvoices = list(vvoice_map.keys())
        assert vvoice_map
        assert vvoices[0] in vvoice_map
        vnotes = vvoice_map[vvoices[0]]
        assert len(vnotes) == 4
        assert TestScore.has_pitch(vnotes, DiatonicPitch.parse('C:4'))
        assert TestScore.has_pitch(vnotes, DiatonicPitch.parse('F:4'))

        # search for notes starting in [3/8, 3/4)
        voice_note_map = score.get_notes_starting_in_wnt_interval(
            Interval(Position(3, 8), Position(3, 4)))
        assert voice_note_map
        for (k, v) in voice_note_map.items():
            print('InstrumentVoice {0}:'.format(k))
            for (k1, v1) in v.items():
                print('    {0} --> [{1}]'.format(k1.instrument,
                                                 ', '.join(str(n)
                                                           for n in v1)))

        cvoice_map = voice_note_map.get(clarinet_instrument_voice)
        cvoices = list(cvoice_map.keys())
        assert cvoice_map
        assert cvoices[0] in cvoice_map
        cnotes = cvoice_map[cvoices[0]]
        assert len(cnotes) == 1
        assert TestScore.has_pitch(cnotes, DiatonicPitch.parse('C:5'))

        vvoice_map = voice_note_map.get(violin_instrument_voice)
        vvoices = list(vvoice_map.keys())
        assert vvoice_map
        assert vvoices[0] in vvoice_map
        vnotes = vvoice_map[vvoices[0]]
        assert len(vnotes) == 3
        assert TestScore.has_pitch(vnotes, DiatonicPitch.parse('D:4'))
        assert TestScore.has_pitch(vnotes, DiatonicPitch.parse('E:4'))
        assert TestScore.has_pitch(vnotes, DiatonicPitch.parse('F:4'))

        duration = score.duration
        print('full wnt duration = {0}'.format(duration))
        assert duration == Duration(1, 1)

        with self.assertRaises(Exception):
            bd = score.beat_duration
            print(bd)

        # 3/4 TS + 60 beats per minute, 1 beat == 1 sec
        score.tempo_sequence.add(TempoEvent(Tempo(60), Position(0)))
        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        bp_duration = score.beat_duration
        print('full beat duration = {0}'.format(bp_duration))

        assert bp_duration == BeatPosition(1, 1)

        real_duration = score.real_duration
        print('real duration = {0}'.format(real_duration))
        assert real_duration == 4000
コード例 #15
0
    def test_score_convert(self):
        print('test_score_convert')

        c = InstrumentCatalog.instance()

        score = Score()

        score.time_signature_sequence.add(
            TimeSignatureEvent(TimeSignature(3, Duration(1, 4)), Position(0)))
        score.tempo_sequence.add(
            TempoEvent(Tempo(60, Duration(1, 4)), Position(0)))

        violin = c.get_instrument("violin")
        violin_instrument_voice = InstrumentVoice(violin, 2)
        violin_voice_0 = violin_instrument_voice.voice(0)
        violin_voice_1 = violin_instrument_voice.voice(1)
        assert violin_voice_0
        assert violin_voice_1
        score.add_instrument_voice(violin_instrument_voice)

        violin_voice_0.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.P), Position(0)))
        violin_voice_0.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.FFF), Position(1, 4)))
        violin_voice_1.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.P), Position(0)))
        violin_voice_1.dynamics_sequence.add(
            DynamicsEvent(Dynamics(Dynamics.FFF), Position(1, 4)))

        # Add notes to the score
        vnote0 = Note(DiatonicPitch(4, 'a'), Duration(1, 8))
        vnote1 = Note(DiatonicPitch(4, 'b'), Duration(1, 8))
        vnote2 = Note(DiatonicPitch(5, 'c'), Duration(1, 8))
        vnote3 = Note(DiatonicPitch(4, 'd'), Duration(1, 8))
        vnote4 = Note(DiatonicPitch(4, 'e'), Duration(1, 8))
        vnote5 = Note(DiatonicPitch(4, 'f'), Duration(1, 8))

        # Set up a violin voice with 6 8th notes
        vline_0 = Line([vnote0, vnote1, vnote2])
        violin_voice_0.pin(vline_0)

        # Set up a violin voice with 6 8th notes
        vline_1 = Line([vnote3, vnote4, vnote5])
        violin_voice_1.pin(vline_1, Offset(1, 16))

        # The test merges these two voices into one.

        svmc = ScoreToVstMidiConverter(score)
        meta_track, tracks = svmc.create({0: 4})
        assert meta_track is not None
        assert tracks is not None

        assert len(tracks) == 1
        assert len(tracks[0]) == 16

        for i in range(0, len(tracks[0])):
            print("{0}: {1}".format(i, tracks[0][i]))

        assert isinstance(tracks[0][0], NoteMessage)
        assert tracks[0][0].msg_type == 144
        assert tracks[0][0].note_value == 69  # A
        assert tracks[0][0].abs_frame_time == 0
        assert tracks[0][0].rel_frame_time == 0

        assert isinstance(tracks[0][3], NoteMessage)
        assert tracks[0][3].msg_type == 144
        assert tracks[0][3].note_value == 62  # D
        assert tracks[0][3].abs_frame_time == 10525
        assert tracks[0][3].rel_frame_time == 10525

        assert isinstance(tracks[0][5], NoteMessage)
        assert tracks[0][5].msg_type == 144
        assert tracks[0][5].note_value == 71  # B
        assert tracks[0][5].abs_frame_time == 21050
        assert tracks[0][5].rel_frame_time == 0

        assert isinstance(tracks[0][4], NoteMessage)
        assert tracks[0][4].msg_type == 128
        assert tracks[0][4].note_value == 69  # A
        assert tracks[0][4].abs_frame_time == 21050
        assert tracks[0][4].rel_frame_time == 10525

        assert isinstance(tracks[0][6], NoteMessage)
        assert tracks[0][6].msg_type == 128
        assert tracks[0][6].note_value == 62  # D
        assert tracks[0][6].abs_frame_time == 31575
        assert tracks[0][6].rel_frame_time == 10525

        assert isinstance(tracks[0][8], NoteMessage)
        assert tracks[0][8].msg_type == 128
        assert tracks[0][8].note_value == 71  # B
        assert tracks[0][8].abs_frame_time == 42100
        assert tracks[0][8].rel_frame_time == 10525