7 sys
.path
= ["./py"] + sys
.path
13 Document
= cbox
.Document
14 Transport
= cbox
.Transport
16 song
= Document
.get_song()
18 # Delete all the tracks and patterns
22 trk
= song
.add_track()
24 # Create a binary blob that contains the MIDI events
26 for noteindex
in range(20):
28 pblob
+= cbox
.Pattern
.serialize_event(noteindex
* 24, 0x90, 36+noteindex
*3, 127)
30 pblob
+= cbox
.Pattern
.serialize_event(noteindex
* 24 + 23, 0x90, 36+noteindex
*3, 0)
32 # This will be the length of the pattern (in pulses). It should be large enough
33 # to fit all the events
34 pattern_len
= 10 * 24 * 2
36 # Create a new pattern object using events from the blob
37 pattern
= song
.pattern_from_blob(pblob
, pattern_len
)
39 # Add an instance (clip) of the pattern to the track at position 0
40 # The clip will contain the whole pattern (it is also possible to insert
41 # a single slice of the pattern)
42 clip
= trk
.add_clip(0, 0, pattern_len
, pattern
)
44 # Stop the song at the end
45 song
.set_loop(pattern_len
, pattern_len
)
47 # Set tempo - the argument must be a float
48 Transport
.set_tempo(160.0)
50 # Send the updated song data to the realtime thread
51 song
.update_playback()
53 print ("Song length (seconds) is %f" % (cbox
.Transport
.ppqn_to_samples(pattern_len
) * 1.0 / Transport
.status().sample_rate
))
55 # The /master object API doesn't have any nice Python wrapper yet, so accessing
56 # it is a bit ugly, still - it works
63 # Get transport information - current position (samples and pulses), current tempo etc.
64 master
= Transport
.status()
65 print (master
.pos_ppqn
)
66 # Query JACK ports, new USB devices etc.