Skip to main content

Posts

Showing posts from December, 2013

Recording MIDI Sessions Automatically - Part 2

Now I need to write the notes to a file, and determine when sessions start and end. This is pretty easy - I just see if any notes have been played in two minutes. If none, it's the end of a session and I can flush to disk. PyGame.midi input events are arrays with two values: another data array, and a timestamp. I normalise the timestamps by subtracting the first timestamp from each subsequent one. The data array is: status, data1, data2, data3. For a note on, this is 144, pitch, velocity, channel. For a note off, my piano is sending 144, pitch, 0, channel. MIDIUtil looked promising for saving this, but it handles the low level note-on/note-off business - data I already have, so I'd have to do complicated stuff to reverse that, pass it to the library which would then undo it. Something simpler is needed: mxm's midi writer .

Recording MIDI Sessions automatically - Part 1

For Christmas I have been given (very kindly!) a Kawai CL26 Digital Piano. In order to feel more deserving of this amazing instrument I've been planning to record my practise session times in order to amortize the cost (in a sense). But why not simply record everything ? My USB/MIDI converter works with raspbian without any extra plugins. Then, using Pygame.midi I can see incoming MIDI information in a polling loop: import pygame.midi import time pygame.midi.init() inputKeyboard = pygame.midi.Input(3) # this is the device id for the midi input, worked out by doing # pygame.midi.get_device_info(1-n) while 1 == 1: while inputKeyboard.poll() == True: print(inputKeyboard.read(1)) time.sleep(0.001) inputKeyboard.close() pygame.midi.quit()