Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
Created April 9, 2011 21:23
Show Gist options
  • Save RyanScottLewis/911786 to your computer and use it in GitHub Desktop.
Save RyanScottLewis/911786 to your computer and use it in GitHub Desktop.
BCR2000/BCF2000 SysEx Messages
require 'midi-winmm'
class Numeric
def to_hex
"%02x" % self
end
end
class String
def to_hex
unpack('U' * length).collect { |x| "%02x" % x }.join
end
end
# Every SysEx message sent to the BCR2000 or BCF2000
# uses a language called BCL or B-Control Language..
# Regrettably, Behringer never released the specs
# which makes it hard as hell to program.
#
# From here on, the BCR2000 and BCF2000 will simply
# be called "BCR" and "BCF", respectably.
# When refering to both devices, I'll simply write "BC".
module BControl
module SysEx
ANY = 0x7F
BCF2000 = 0x14
BCR2000 = 0x15
class Message
attr_accessor :id, :model, :command, :data
def initialize(&blk)
@id = ANY
end
# IDs on the BC range from 1 to 16 on the devices
# but 0 to 15 in SysEx messages.
# When we set the value here, we will decrease
# the value by 1 for the message.
#
# Basically, just set this to the value
# of encoder 5 in the BC global setup manu.
def id=(val)
val = val.to_s
@id = (1..16).include?(val) ? val-1 : ANY;
end
def to_s
"f0002032#{[@id, @model, @command, @data].collect{ |i| i.to_hex }.join}f7"
end
end
end
end
# ======================================================
# Create a new SysEx message, set the id & model
# Set the command to "select preset" and
# select preset 3 (it says 2 but SysEx is -1)
msg = BControl::SysEx::Message.new
msg.id = 1
msg.model = BControl::SysEx::BCR2000
msg.command = 0x22
msg.data = 2
puts msg.to_s # => This is the actual SysEx message
# tested with midi-winmm,
# but I assume will work in Linux
# with alsa-rawmidi
# Find my BCR2000 in a roundabout way..
# open it, send the sysex message, then close it. \m/
device = MIDIWinMM::Output.all.find { |output|
output.instance_eval { @name } == "BCR2000"
}
device.open
device.puts_bytestr(msg.to_s)
device.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment