Пример #1
0
def create_miditable():
    """This function creates a MidiTable populated with all types of midi messages that have been
    implemented in kenmido module in order to test the correct functionality of encoding and decoding
    midi data."""

    track0 = MidiTable(
        5)  # A specialized data structure to implement musical score data

    track0.TrackName('Song')  # track=0 time=0 by default
    track0.TempoSet(85)
    track0.TimeSignature(4, 4, track=0)
    track0.sysex('Hello sysex World')
    track0.SequenceNumber(365)
    track0.Copyright('Anustuv Pal')
    track0.InstrumentName('Free VST')
    track0.Marker('A marker', time=240)
    track0.CueMarker('A cue message', time=240)
    track0.DeviceName('A device')
    track0.ChannelPrefix(13)
    track0.MidiPort(1)
    track0.SmpteOffset()
    track0.KeySignature('Gm', time=240)
    track0.SequencerSpecific((1, 1, 2, 3, 5, 8, 13))
    # track0.meta(EndOfTrack)  # end of tracks are inserted automatically

    track1 = MidiTable(5, track=1, channel=0)
    track1.TrackName('Track1')
    track1.Text('This is a text meta message in track 1')
    track1.control(time=0, control=CONTROLS['Channel Volume'], cc_val=100)
    track1.control(time=1, control=CONTROLS['Pan'], cc_val=95, channel=1)
    track1.program(program=PROGRAMS['Clavi'])
    track1.program(program=PROGRAMS['Electric Piano'], time=480)
    track1.meta(metaclasses.Lyrics, 'A word', time=240)

    score = MidiTable(4, track=1,
                      channel=0)  # Mechanism to write notes into the table
    for time, noteval in zip(range(0, 4 * 240, 240), [61, 65, 68, 72]):
        score.note_on(time=time,
                      noteval=noteval,
                      score_d=240,
                      midi_d=240,
                      notevel=70)

    score = merge_tables(track0, track1, score)  # simple concatenation
    score.fix_eots()  # ensure end-of-tracks find their appropriate position
    score.insert_note_offs()
    score.remove_empty_rows()
    score.encode_table()
    tprint(score)
    return score
Пример #2
0
def generate_testtable():
    testtable = MidiTable(20, channel=1, track=1)
    # print(testtable.maxtime)
    testtable.TrackName('Song 1', track=0, channel=0)
    testtable.TempoSet(105)
    testtable.TimeSignature(4, 4)
    testtable.TrackName('Track 1')
    testtable.control('volume', 100)
    testtable.control('pan', 67)
    testtable.bend(0)
    testtable.Marker('A marker', time=240)
    testtable.Lyrics('Some words...', time=480)
    testtable.note_on(time=0, noteval=60, score_d=480)
    testtable.note_on(time=480, noteval=62, score_d=480)
    testtable.note_on(time=960, noteval=64, score_d=480)
    testtable.note_on(time=1280, noteval=65, score_d=480)

    testtable.cleanup()
    return testtable
Пример #3
0
from kenmido import MidiTable, Sequencer, portopen, play
from kenmido.rows import Mtypes
from theorymuse import tprint, Printer

Printer.midi_mode()
a = MidiTable(20, channel=1, track=1)
a.TrackName('Song 1', track=0, channel=0)
a.TempoSet(105)
a.TimeSignature(4, 4)
a.TrackName('Track 1')
a.control('volume', 100)
a.control('pan', 67)
a.bend(0)
a.Marker('A marker', time=240)
a.Lyrics('Some words...', time=480)
a.note_on(time=0, noteval=60, score_d=480, midi_f=1)
a.note_on(time=480, noteval=62, score_d=480, midi_f=1)
a.note_on(time=960, noteval=64, score_d=480, midi_f=1)
a.note_on(time=960 + 240, noteval=65, score_d=240, midi_f=1)
a.fix_eots()
a.insert_note_offs()
a.remove_empty_rows()
a.sort()
a.encode_table()
a.abs_to_reltime()
print(a.maxtime)
tprint(a)
with portopen('loopMIDI'):
    play(a, noloops=3)