add new sigc++2 directory
[ardour.git] / libs / surfaces / mackie / scripts / parse.rb
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 "rexml/document"
19 file = File.new( ARGV[0] )
20 doc = REXML::Document.new file
21
22 # fetch the node containing the controls
23 controls = XPath.first( doc, 'Session/ControlProtocols/Protocol[@name="Generic MIDI"]/controls' )
24
25 channel = 1
26
27 # A Control is a button or slider. It has an internal ID
28 # an incoming MIDI message, and an outgoing midi message
29 class Control
30         
31 end
32
33 # Strips have solo,rec,mute,pan,fader
34 # Strips have midi input
35 # Strips have midi output
36 # Strips have an XML representation, or something like that
37 class Strip
38         def initialize( node )
39                 @solo = node.elements['solo']
40                 @mute = node.elements['mute']
41                 @rec = node.elements['recenable']
42                 @fader = node.elements['IO/gaincontrol']
43                 @panner = node.elements['IO/Panner/StreamPanner/panner']
44         end
45 end
46
47 # This knows how to extract a set of controls from a Route
48
49 doc.elements.each( 'Session/Routes/Route' ) do |node|
50         strip = Strip.new( node )
51         
52    controls.add_element( 'mute',
53                 'id' => mute.attribute('id').value,
54                 'event' => "0xb0",
55                 'channel' => channel.to_s,
56                 'additional' => "0x41"
57         )
58
59 end
60
61 pp controls.elements