Repository navigation
Expand file tree
/
Copy pathseqtest3.py
More file actions
executable file
·71 lines (58 loc) · 1.84 KB
/
Copy pathseqtest3.py
File metadata and controls
executable file
·71 lines (58 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /usr/bin/python
# Sample code for pyalsa Sequencer binding
# by Aldrin Martoq <amartoq@dcc.uchile.cl>
# version 2008012401 (UTC: 1201153962 secs since the epoch)
#
# This code is in the public domain,
# use it as base for creating your pyalsa
# sequencer application.
import sys
sys.path.insert(0, '..')
from pyalsa.alsaseq import *
import time
from alsamemdebug import debuginit, debug, debugdone
debuginit()
def findmidiport():
for connections in seq.connection_list():
cname, cid, ports = connections
# skip midi through
if cname == 'Midi Through':
continue
for port in ports:
pname, pid, pconns = port
pinfo = seq.get_port_info(pid, cid)
type = pinfo['type']
caps = pinfo['capability']
if type & SEQ_PORT_TYPE_MIDI_GENERIC and caps & (SEQ_PORT_CAP_WRITE):
print("Using port: %s:%s" % (cname, pname))
return (cid, pid)
print("No midi port found -- install timidity or other software synth for testing!")
sys.exit(0)
# create sequencer
seq = Sequencer()
# find midi port
cid, pid = findmidiport()
# create a queue
queue = seq.create_queue()
seq.start_queue(queue)
tempo, ppq = seq.queue_tempo(queue)
print("tempo: %d ppq: %d" % (tempo, ppq))
# play notes: DO RE MI FA SOL LA
notes = [0x40, 0x42, 0x44, 0x45, 0x47, 0x49]
event = SeqEvent(SEQ_EVENT_NOTE)
for note in notes:
event.dest = (cid, pid)
event.queue = queue
event.time += ppq
event.set_data({'note.note' : note, 'note.velocity' : 64, 'note.duration' : ppq , 'note.off_velocity' : 64})
print('event: %s %s' % (event, event.get_data()))
seq.output_event(event)
seq.drain_output()
seq.sync_output_queue()
# stop queue and delete queue
seq.stop_queue(queue)
seq.delete_queue(queue)
debug([seq])
# close sequencer
del seq
debugdone()