Merge pull request #1 from atsampson/master
[calfbox.git] / usb_api_example.py
blob15e518ef6d7609ff239d3ddf4033e7ecf99ec248
1 from calfbox import cbox
3 def cmd_dumper(cmd, fb, args):
4 print ("%s(%s)" % (cmd, ",".join(list(map(repr,args)))))
6 cbox.init_engine()
8 cbox.Config.add_section("drumpattern:pat1", """
9 title=Straight - Verse
10 beats=4
11 track1=bd
12 track2=sd
13 track3=hh
14 track4=ho
15 bd_note=c1
16 sd_note=d1
17 hh_note=f#1
18 ho_note=a#1
19 bd_trigger=9... .... 9.6. ....
20 sd_trigger=.... 9..5 .2.. 9...
21 hh_trigger=9353 7353 7353 73.3
22 ho_trigger=.... .... .... ..3.
23 """)
25 cbox.Config.set("io", "use_usb", 1)
26 cbox.start_audio(cmd_dumper)
28 global Document
29 Document = cbox.Document
31 status = cbox.JackIO.status()
32 client_name = status.client_name
33 print ("Client type: %s" % status.client_type)
34 print ("Client name: %s" % client_name)
35 print ("Audio inputs: %d, outputs: %d" % (status.audio_inputs, status.audio_outputs))
36 print ("Period: %d frames" % (status.buffer_size))
37 print ("Sample rate: %d frames/sec" % (status.sample_rate))
38 print ("Output resolution: %d bits/sample" % (status.output_resolution))
39 print ("MIDI input devices: %s" % (status.midi_input))
40 #cbox.JackIO.create_midi_output('drums', 'system:midi_playback_1')
42 scene = Document.get_scene()
43 scene.clear()
44 instrument = scene.add_new_instrument_layer("test_sampler", "sampler").get_instrument()
45 pgm_no = instrument.engine.get_unused_program()
46 pgm = instrument.engine.load_patch_from_file(pgm_no, 'synthbass.sfz', 'SynthBass')
47 instrument.engine.set_patch(1, pgm_no)
48 instrument.engine.set_patch(10, pgm_no)
50 song = Document.get_song()
51 track = song.add_track()
52 pattern = song.load_drum_pattern("pat1")
53 track.add_clip(0, 0, pattern.status().loop_end, pattern)
54 song.set_loop(0, pattern.status().loop_end)
55 song.update_playback()
56 cbox.Transport.play()
58 print("Ready!")
60 while True:
61 cbox.call_on_idle(cmd_dumper)