Merge pull request #1 from atsampson/master
[calfbox.git] / adhoc_example.py
blobf7a594f6355df4cb513799db10e7947d7262eff6
1 import os
2 import sys
3 import struct
4 import time
5 import unittest
7 sys.path = ["./py"] + sys.path
9 import cbox
11 global Document
12 global Transport
13 Document = cbox.Document
14 Transport = cbox.Transport
16 song = Document.get_song()
18 # Delete all the tracks and patterns
19 song.clear()
21 # Create a binary blob that contains the MIDI events
22 pblob = bytes()
23 for noteindex in range(20):
24 # note on
25 pblob += cbox.Pattern.serialize_event(noteindex * 12, 0x90, 36+noteindex*3, 127)
26 # note off
27 pblob += cbox.Pattern.serialize_event(noteindex * 12 + 11, 0x90, 36+noteindex*3, 0)
29 # This will be the length of the pattern (in pulses). It should be large enough
30 # to fit all the events
31 pattern_len = 10 * 24 * 2
33 # Create a new pattern object using events from the blob
34 pattern = song.pattern_from_blob(pblob, pattern_len)
36 retrig = 10
37 while True:
38 retrig -= 1
39 if retrig <= 0:
40 print ("Triggering adhoc pattern with ID 1")
41 Document.get_scene().play_pattern(pattern, 240, 1)
42 retrig = 10
43 # Query JACK ports, new USB devices etc.
44 cbox.call_on_idle()
45 time.sleep(0.1)