3 """pyalsamidi at http://infohost.nmt.edu/~dbaird/software/
4 --> depends on ubuntu pkg libasound2-dev
6 n3->rdf convertor at http://www.w3.org/DesignIssues/Notation3.html
8 almost related: http://lists.w3.org/Archives/Public/www-archive/2001Nov/0033
16 more ubuntu pkg needed:
24 import os, select, time, xmlrpclib, socket
25 from twisted.internet import reactor, tksupport, defer
26 from pyalsamidi import pyalsamidi as amidi
27 from logsetup import commonlogsetup
29 from rdfaction import RoomAction
31 log = commonlogsetup(filename=None)
36 self.last_note_time = 0
37 self.max_pause_time = .5 # sec
39 self.room_action = RoomAction()
41 #self.action([60,65]) # tester
44 if ev.data.__class__ != amidi.MidiEvent.NoteOn:
48 if now - self.last_note_time > self.max_pause_time:
51 self.last_note_time = now
52 self.phrase.append(ev.data.note)
55 matched = self.action(self.phrase)
59 if isinstance(e, (KeyboardInterrupt, SystemExit)):
64 def action(self, phrase):
65 phrase_literal = RDF.Node(" ".join(map(str, phrase)))
66 phrase_quoted_literal = '"%s"' % phrase_literal #?
67 log.info("checking phrase %s" % phrase_quoted_literal)
69 return self.room_action.fire(
70 "midi:notes",#"<http:/projects.bigasterisk.com/midi/notes>",
71 phrase_quoted_literal)
73 seq = amidi.Sequencer('Test Sequencer')
74 inp = seq.create_midiin('Test Midi In')
76 outp = seq.create_midiout('Test Midi Out')
77 queue = seq.create_queue()
79 queue.set_bpm(120, ppq)
82 # If you do not have a musical keyboard connected to 64:0, you might
83 # need to modify this line:
84 os.system('aconnect -t %d 64:0 %d:%d' % (queue.id, seq.id, inp.id))
85 os.system('aconnect -t %d %d:%d 64:0' % (queue.id, seq.id, outp.id))
90 a, _, _ = select.select([inp], [], [], .1)
91 while (inp in a) or inp.events_pending():