diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-04-08 14:11:00 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-04-08 14:11:00 +0000 |
commit | c72287e67d82e254f4cd089f8e17a16bf89e2335 (patch) | |
tree | 51984ca003e84f74d40839313ab3161267fda0b2 /libs/surfaces/mackie/controls.cc | |
parent | 05b36d00929a28a65e19ffffddb2a1b624b780d5 (diff) |
MCP: major redesign of control instantiation; continuing code reformatting
git-svn-id: svn://localhost/ardour2/branches/3.0@11824 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/surfaces/mackie/controls.cc')
-rw-r--r-- | libs/surfaces/mackie/controls.cc | 274 |
1 files changed, 161 insertions, 113 deletions
diff --git a/libs/surfaces/mackie/controls.cc b/libs/surfaces/mackie/controls.cc index 9369bb2b62..c26d0cd709 100644 --- a/libs/surfaces/mackie/controls.cc +++ b/libs/surfaces/mackie/controls.cc @@ -1,4 +1,4 @@ -/* + /* Copyright (C) 2006,2007 John Anderson This program is free software; you can redistribute it and/or modify @@ -15,171 +15,170 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "controls.h" -#include "types.h" -#include "mackie_midi_builder.h" #include <iostream> #include <iomanip> #include <sstream> +#include "controls.h" +#include "types.h" +#include "mackie_midi_builder.h" +#include "surface.h" + using namespace Mackie; using namespace std; -uint32_t Control::button_cnt = 0; -uint32_t Control::pot_cnt = 0; -uint32_t Control::fader_cnt = 0; -uint32_t Control::led_cnt = 0; -uint32_t Control::jog_cnt = 0; - -void Group::add( Control & control ) +void Group::add (Control& control) { - _controls.push_back( &control ); + _controls.push_back (&control); } -Strip::Strip( const std::string & name, int index ) - : Group( name ) - , _solo( 0 ) - , _recenable( 0 ) - , _mute( 0 ) - , _select( 0 ) - , _vselect( 0 ) - , _fader_touch( 0 ) - , _vpot( 0 ) - , _gain( 0 ) - , _index( index ) +Strip::Strip (const std::string& name, int index) + : Group (name) + , _solo (0) + , _recenable (0) + , _mute (0) + , _select (0) + , _vselect (0) + , _fader_touch (0) + , _vpot (0) + , _gain (0) + , _index (index) { + /* master strip only */ } +Strip::Strip (Surface& surface, const std::string& name, int index, int unit_index, StripControlDefinition* ctls) + : Group (name) + , _solo (0) + , _recenable (0) + , _mute (0) + , _select (0) + , _vselect (0) + , _fader_touch (0) + , _vpot (0) + , _gain (0) + , _index (index) +{ + /* build the controls for this track, which will automatically add them + to the Group + */ + + for (uint32_t i = 0; ctls[i].name[0]; ++i) { + ctls[i].factory (surface, ctls[i].base_id + unit_index, unit_index+1, ctls[i].name, *this); + } +} + /** TODO could optimise this to use enum, but it's only called during the protocol class instantiation. - - generated using - - irb -r controls.rb - sf=Surface.new - sf.parse - controls = sf.groups.find{|x| x[0] =~ /strip/}.each{|x| puts x[1]} - controls[1].each {|x| puts "\telse if ( control.name() == \"#{x.name}\" )\n\t{\n\t\t_#{x.name} = reinterpret_cast<#{x.class.name}*>(&control);\n\t}\n"} */ -void Strip::add( Control & control ) +void Strip::add (Control & control) { - Group::add( control ); - if ( control.name() == "gain" ) - { + Group::add (control); + + if (control.name() == "gain") { _gain = reinterpret_cast<Fader*>(&control); - } - else if ( control.name() == "vpot" ) - { + } else if (control.name() == "vpot") { _vpot = reinterpret_cast<Pot*>(&control); - } - else if ( control.name() == "recenable" ) - { + } else if (control.name() == "recenable") { _recenable = reinterpret_cast<Button*>(&control); - } - else if ( control.name() == "solo" ) - { + } else if (control.name() == "solo") { _solo = reinterpret_cast<Button*>(&control); - } - else if ( control.name() == "mute" ) - { + } else if (control.name() == "mute") { _mute = reinterpret_cast<Button*>(&control); - } - else if ( control.name() == "select" ) - { + } else if (control.name() == "select") { _select = reinterpret_cast<Button*>(&control); - } - else if ( control.name() == "vselect" ) - { + } else if (control.name() == "vselect") { _vselect = reinterpret_cast<Button*>(&control); - } - else if ( control.name() == "fader_touch" ) - { + } else if (control.name() == "fader_touch") { _fader_touch = reinterpret_cast<Button*>(&control); - } - else if ( control.type() == Control::type_led || control.type() == Control::type_led_ring ) - { - // do nothing - cout << "Strip::add not adding " << control << endl; - } - else - { + } else if (control.type() == Control::type_led || control.type() == Control::type_led_ring) { + // relax + } else { ostringstream os; os << "Strip::add: unknown control type " << control; - throw MackieControlException( os.str() ); + throw MackieControlException (os.str()); } } -Control::Control( int id, int ordinal, std::string name, Group & group ) -: _id( id ) -, _ordinal( ordinal ) -, _name( name ) -, _group( group ) -, _in_use( false ) +Control::Control (int id, int ordinal, std::string name, Group & group) + : _id (id) + , _ordinal (ordinal) + , _name (name) + , _group (group) + , _in_use (false) { } -/** - generated with - -controls[1].each do |x| - puts <<EOF -#{x.class.name} & Strip::#{x.name}() -{ - if ( _#{x.name} == 0 ) - throw MackieControlException( "#{x.name} is null" ); - return *_#{x.name}; -} -EOF -end -*/ -Fader & Strip::gain() +Fader& +Strip::gain() { - if ( _gain == 0 ) - throw MackieControlException( "gain is null" ); + if (_gain == 0) { + throw MackieControlException ("gain is null"); + } return *_gain; } -Pot & Strip::vpot() + +Pot& +Strip::vpot() { - if ( _vpot == 0 ) - throw MackieControlException( "vpot is null" ); + if (_vpot == 0) { + throw MackieControlException ("vpot is null"); + } return *_vpot; } -Button & Strip::recenable() + +Button& +Strip::recenable() { - if ( _recenable == 0 ) - throw MackieControlException( "recenable is null" ); + if (_recenable == 0) { + throw MackieControlException ("recenable is null"); + } return *_recenable; } -Button & Strip::solo() + +Button& +Strip::solo() { - if ( _solo == 0 ) - throw MackieControlException( "solo is null" ); + if (_solo == 0) { + throw MackieControlException ("solo is null"); + } return *_solo; } -Button & Strip::mute() +Button& +Strip::mute() { - if ( _mute == 0 ) - throw MackieControlException( "mute is null" ); + if (_mute == 0) { + throw MackieControlException ("mute is null"); + } return *_mute; } -Button & Strip::select() + +Button& +Strip::select() { - if ( _select == 0 ) - throw MackieControlException( "select is null" ); + if (_select == 0) { + throw MackieControlException ("select is null"); + } return *_select; } -Button & Strip::vselect() + +Button& +Strip::vselect() { - if ( _vselect == 0 ) - throw MackieControlException( "vselect is null" ); + if (_vselect == 0) { + throw MackieControlException ("vselect is null"); + } return *_vselect; } -Button & Strip::fader_touch() + +Button& +Strip::fader_touch() { - if ( _fader_touch == 0 ) - throw MackieControlException( "fader_touch is null" ); + if (_fader_touch == 0) { + throw MackieControlException ("fader_touch is null"); + } return *_fader_touch; } @@ -201,9 +200,9 @@ Control::set_in_use (bool in_use) _in_use = in_use; } -ostream & Mackie::operator << ( ostream & os, const Mackie::Control & control ) +ostream & Mackie::operator << (ostream & os, const Mackie::Control & control) { - os << typeid( control ).name(); + os << typeid (control).name(); os << " { "; os << "name: " << control.name(); os << ", "; @@ -221,9 +220,9 @@ ostream & Mackie::operator << ( ostream & os, const Mackie::Control & control ) return os; } -std::ostream & Mackie::operator << ( std::ostream & os, const Strip & strip ) +std::ostream & Mackie::operator << (std::ostream & os, const Strip & strip) { - os << typeid( strip ).name(); + os << typeid (strip).name(); os << " { "; os << "has_solo: " << boolalpha << strip.has_solo(); os << ", "; @@ -244,3 +243,52 @@ std::ostream & Mackie::operator << ( std::ostream & os, const Strip & strip ) return os; } + +Control* +Button::factory (Surface& surface, int id, int ordinal, const char* name, Group& group) +{ + Button* b = new Button (id, ordinal, name, group); + surface.buttons[id] = b; + surface.controls.push_back (b); + group.add (*b); + return b; +} + +Control* +Fader::factory (Surface& surface, int id, int ordinal, const char* name, Group& group) +{ + Fader* f = new Fader (id, ordinal, name, group); + surface.faders[id] = f; + surface.controls.push_back (f); + group.add (*f); + return f; +} + +Control* +Pot::factory (Surface& surface, int id, int ordinal, const char* name, Group& group) +{ + Pot* p = new Pot (id, ordinal, name, group); + surface.pots[id] = p; + surface.controls.push_back (p); + group.add (*p); + return p; +} + +Control* +Led::factory (Surface& surface, int id, int ordinal, const char* name, Group& group) +{ + Led* l = new Led (id, ordinal, name, group); + surface.leds[id] = l; + surface.controls.push_back (l); + group.add (*l); + return l; +} + +Control* +Jog::factory (Surface& surface, int id, int ordinal, const char* name, Group& group) +{ + Jog* j = new Jog (id, ordinal, name, group); + surface.controls.push_back (j); + group.add (*j); + return j; +} |