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.
23 while !File.exist? ARGV[0]
27 file = File.open( ARGV[0], 'r+' )
28 mck = Mackie.new( file )
30 # faders to minimum. bcf2000 doesn't respond
31 mck.write_sysex "\x61"
33 # all leds off. bcf2000 doesn't respond
34 mck.write_sysex "\x62"
36 # get version. comes back as ASCII bytes
37 version = mck.sysex "\x13\x00"
38 puts "version: #{version.map{|x| x.chr}}"
40 # respond to control movements
41 while bytes = file.read( 3 )
42 puts "received: %02.x %02.x %02.x" % [ bytes[0], bytes[1], bytes[2] ]
44 case bytes[0] & 0b11110000
46 # fader moved, so respond if move is OK
52 # do nothing - touch detection
53 puts "touch detect: %02.x" % bytes[2]
55 # treat all buttons as toggles
58 # only toggle on release. Not working. All buttons send press
59 # and then release signals
61 if buttons.include?( button_id )
63 puts "button id #{buttons[button_id]} to #{!buttons[button_id]}"
64 buttons[button_id] = !buttons[button_id]
66 # create a new button as on
67 puts "adding button id #{button_id}"
68 buttons[button_id] = true
70 bytes[2] = buttons[button_id] ? 0x7f : 0
75 # pots, jog wheel, external
79 pot_id = bytes[1] & 0b00000111
80 direction = bytes[2] & 0b01000000
81 delta = bytes[2] & 0b00111111
82 sign = direction == 0 ? 1 : -1
84 if pots.include? pot_id
85 current_led_pos = pots[pot_id]
87 current_led_pos = pots[pot_id] = 6
89 new_led_pos = current_led_pos + sign
93 when new_led_pos >= 11
99 pots[pot_id] = new_led_pos
101 puts "pot #{pot_id} turned #{sign} #{direction == 0 ? 'clockwise' : 'widdershins'}: %02.x to #{new_led_pos}" % delta
105 output[2] = 0b01000000
111 mode = pot_id < 4 ? pot_id : 0
112 output[2] |= ( mode << 4 )
113 output[2] += ( new_led_pos ) & 0b00001111
115 # external controller
120 puts "don't know what this means"
126 puts "sending: %02.x %02.x %02.x" % [ output[0], output[1], output[2] ]
128 res = file.write output
134 file = File.open ARGV[0], 'r+'