2 # Copyright (C) 2006,2007 John Anderson
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 while !File.exist? ARGV[0]
25 #mapping_csv = ARGV[1] || "mackie-controls.csv"
27 puts "mapping_csv: #{mapping_csv}"
30 file = File.open ARGV[0], 'r+'
31 mck = Mackie.new( file )
34 response = mck.sysex( "\x00" )
35 puts "response: #{response.to_hex}"
37 # decode host connection query
40 puts "expected 01, got " + response.to_hex.inspect
43 serial = response[1..7]
44 challenge = response[8..11]
46 serial: #{serial.to_hex.inspect}
47 challenge: #{challenge.to_hex.inspect}
50 # send host connection reply
51 response = mck.sysex( "\x02" + serial.pack('C*') + challenge.pack('C*') )
53 # decode host connection confirmation
56 puts "expected 03, got " + response.to_hex.inspect
60 serial = response[1..7]
62 serial: #{serial.to_hex.inspect}
65 # faders to minimum. bcf2000 doesn't respond
66 #file.write( hdr + "\x61\xf7" )
68 # all leds off. bcf2000 doesn't respond
69 #file.write( hdr + "\x62\xf7" )
71 # get version. comes back as ASCII bytes
72 version = mck.sysex( "\x13\x00" )
73 puts "version: #{version.map{|x| x.chr}}"
75 # write a welcome message. bcf2000 responds with exact
76 # string but doesn't display anything
78 #~ file.write hdr + "\x12\x3fLCDE\xf7"
80 #~ answer = read_sysex file
81 #~ puts "answer: #{answer[hdr.length..-1].map{|x| x.chr}}"
83 # write to BBT display
84 #~ file.write hdr + "\x10LCDE\xf7"
87 #~ while ( nc = file.read( 1 ) )[0] != 0xf7
90 #~ puts "bbt: #{bbt[hdr.length..-1].map{|x| x.chr}}"
92 # write 7-segment display
93 #~ file.write hdr + "\x11LCDE\xf7"
96 # go offline. bcf2000 doesn't respond
97 #~ file.write( hdr + "\x0f\x7f\xf7" )
102 File.open( mapping_csv ) { |f| control_data = f.read }
103 sf.parse( control_data )
105 # send all faders to 0, but bounce them first
106 # otherwise the bcf gets confused
107 sf.midis[0xe0].values.find_all{|x| x.class == Fader}.each do |x|
109 bytes[0] = 0xe0 + x.ordinal - 1
112 file.write bytes.pack( 'C*' )
113 bytes[0] = 0xe0 + x.ordinal - 1
116 file.write bytes.pack( 'C*' )
120 # respond to control movements
121 while bytes = mck.file.read( 3 )
122 print "received: %02.x %02.x %02.x" % [ bytes[0], bytes[1], bytes[2] ]
123 midi_type = bytes[0] & 0b11110000
125 control_id = sf.types[midi_type].mask_for_id( bytes )
126 control = sf.midis[midi_type][control_id]
128 print " Control Type: %-7s, " % sf.types[midi_type]
129 print "id: %4i" % control_id
130 print ", control: %15s" % ( control ? control.name : "nil control" )
131 print ", %15s" % ( control ? control.group.name : "nil group" )