~ubuntu-branches/ubuntu/vivid/ardour/vivid-proposed

« back to all changes in this revision

Viewing changes to libs/surfaces/mackie/scripts/host.rb

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler, Jaromír Mikeš, Felipe Sateler
  • Date: 2014-05-22 14:39:25 UTC
  • mfrom: (29 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: package-import@ubuntu.com-20140522143925-vwqfo9287pmkrroe
Tags: 1:2.8.16+git20131003-3
* Team upload

[ Jaromír Mikeš ]
* Add -dbg package

[ Felipe Sateler ]
* Upload to experimental

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/ruby
 
2
# Copyright (C) 2006,2007 John Anderson
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
 
 
18
require 'controls.rb'
 
19
require 'mackie.rb'
 
20
 
 
21
if ARGV.size != 2
 
22
  puts "#$0 /dev/snd/midiXXXX control-file.csv"
 
23
  exit 1
 
24
end
 
25
 
 
26
while !File.exist? ARGV[0]
 
27
  sleep 0.010
 
28
end
 
29
 
 
30
#mapping_csv = ARGV[1] || "mackie-controls.csv"
 
31
mapping_csv = ARGV[1]
 
32
puts "mapping_csv: #{mapping_csv}"
 
33
puts ""
 
34
 
 
35
file = File.open ARGV[0], 'r+'
 
36
mck = Mackie.new( file )
 
37
 
 
38
# faders to minimum. bcf2000 doesn't respond
 
39
mck.write_sysex "\x61"
 
40
 
 
41
# all leds off. bcf2000 doesn't respond
 
42
mck.write_sysex "\x62"
 
43
 
 
44
# get version. comes back as ASCII bytes
 
45
version = mck.sysex "\x13\x00"
 
46
puts "version: #{version.map{|x| x.chr}}"
 
47
 
 
48
# write a welcome message. bcf2000 responds with exact
 
49
# string but doesn't display anything
 
50
# 0 offset,
 
51
#~ file.write hdr + "\x12\x3fLCDE\xf7"
 
52
#~ file.flush
 
53
#~ answer = read_sysex file
 
54
#~ puts "answer: #{answer[hdr.length..-1].map{|x| x.chr}}"
 
55
 
 
56
# write to BBT display
 
57
#~ file.write hdr + "\x10LCDE\xf7"
 
58
#~ file.flush
 
59
#~ bbt = []
 
60
#~ while ( nc = file.read( 1 ) )[0] != 0xf7
 
61
  #~ bbt << nc[0]
 
62
#~ end
 
63
#~ puts "bbt: #{bbt[hdr.length..-1].map{|x| x.chr}}"
 
64
 
 
65
# write 7-segment display
 
66
#~ file.write hdr + "\x11LCDE\xf7"
 
67
#~ file.flush
 
68
 
 
69
# go offline. bcf2000 doesn't respond
 
70
#~ file.write( hdr + "\x0f\x7f\xf7" )
 
71
#~ file.flush
 
72
 
 
73
sf = Surface.new
 
74
control_data = ""
 
75
File.open( mapping_csv ) { |f| control_data = f.read }
 
76
sf.parse( control_data )
 
77
 
 
78
# send all faders to 0, but bounce them first
 
79
# otherwise the bcf gets confused
 
80
sf.midis[0xe0].values.find_all{|x| x.class == Fader}.each do |x|
 
81
  bytes = Array.new
 
82
  bytes[0] = 0xe0 + x.ordinal - 1
 
83
  bytes[1] = 0x1
 
84
  bytes[2] = 0x1
 
85
  file.write bytes.pack( 'C*' )
 
86
  bytes[0] = 0xe0 + x.ordinal - 1
 
87
  bytes[1] = 0x0
 
88
  bytes[2] = 0x0
 
89
  file.write bytes.pack( 'C*' )
 
90
end
 
91
file.flush
 
92
 
 
93
# respond to control movements
 
94
while bytes = mck.file.read( 3 )
 
95
  print "received: %02.x %02.x %02.x" % [ bytes[0], bytes[1], bytes[2] ]
 
96
  midi_type = bytes[0] & 0b11110000
 
97
 
 
98
  control_id = sf.types[midi_type].mask_for_id( bytes )
 
99
  control = sf.midis[midi_type][control_id]
 
100
  
 
101
  print " Control Type: %-7s, " % sf.types[midi_type]
 
102
  print "id: %4x" % control_id
 
103
  print ", control: %15s" % ( control ? control.name : "nil control" )
 
104
  print ", %15s" % ( control ? control.group.name : "nil group" )
 
105
  print "\n"
 
106
end