e9e875b7027cf5edbf6e959c1e91934d3dfe3805
[ardour.git] / libs / surfaces / generic_midi / midifunction.cc
1 /*
2     Copyright (C) 2009 Paul Davis
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
19 #include <cstring>
20
21 #include "midi++/port.h"
22
23 #include "midifunction.h"
24 #include "generic_midi_control_protocol.h"
25
26 #include "pbd/compose.h"
27
28 #include "ardour/debug.h"
29
30 using namespace MIDI;
31 using namespace PBD;
32
33 MIDIFunction::MIDIFunction (MIDI::Parser& p)
34         : MIDIInvokable (p)
35 {
36 }
37
38 MIDIFunction::~MIDIFunction ()
39 {
40 }
41
42 int
43 MIDIFunction::setup (GenericMidiControlProtocol& ui, const std::string& invokable_name, const std::string& arg, MIDI::byte* msg_data, size_t data_sz)
44 {
45         MIDIInvokable::init (ui, invokable_name, msg_data, data_sz);
46
47         _argument = arg;
48
49         if (strcasecmp (_invokable_name.c_str(), "transport-stop") == 0) {
50                 _function = TransportStop;
51         } else if (strcasecmp (_invokable_name.c_str(), "transport-roll") == 0) {
52                 _function = TransportRoll;
53         } else if (strcasecmp (_invokable_name.c_str(), "transport-zero") == 0) {
54                 _function = TransportZero;
55         } else if (strcasecmp (_invokable_name.c_str(), "transport-start") == 0) {
56                 _function = TransportStart;
57         } else if (strcasecmp (_invokable_name.c_str(), "transport-end") == 0) {
58                 _function = TransportEnd;
59         } else if (strcasecmp (_invokable_name.c_str(), "loop-toggle") == 0) {
60                 _function = TransportLoopToggle;
61         } else if (strcasecmp (_invokable_name.c_str(), "rec-enable") == 0) {
62                 _function = TransportRecordEnable;
63         } else if (strcasecmp (_invokable_name.c_str(), "rec-disable") == 0) {
64                 _function = TransportRecordDisable;
65         } else if (strcasecmp (_invokable_name.c_str(), "next-bank") == 0) {
66                 _function = NextBank;
67         } else if (strcasecmp (_invokable_name.c_str(), "prev-bank") == 0) {
68                 _function = PrevBank;
69         } else if (strcasecmp (_invokable_name.c_str(), "set-bank") == 0) {
70                 if (_argument.empty()) {
71                         return -1;
72                 }
73                 _function = SetBank;
74         } else if (strcasecmp (_invokable_name.c_str(), "select") == 0) {
75                 if (_argument.empty()) {
76                         return -1;
77                 }
78                 _function = Select;
79         } else if (strcasecmp (_invokable_name.c_str(), "track-set-solo") == 0) {
80                 if (_argument.empty()) {
81                         return -1;
82                 }
83                 _function = TrackSetSolo;
84         } else if (strcasecmp (_invokable_name.c_str(), "track-set-mute") == 0) {
85                 if (_argument.empty()) {
86                         return -1;
87                 }
88                 _function = TrackSetMute;
89         } else {
90                 return -1;
91         }
92
93         return 0;
94 }
95
96 void
97 MIDIFunction::execute ()
98 {
99         switch (_function) {
100         case NextBank:
101                 _ui->next_bank();
102                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: next_bank\n");
103                 break;
104
105         case PrevBank:
106                 _ui->prev_bank();
107                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: prev_bank\n");
108                 break;
109
110         case SetBank:
111                 if (!_argument.empty()) {
112                         uint32_t bank;
113                         sscanf (_argument.c_str(), "%d", &bank);
114                         _ui->set_current_bank (bank);
115                         DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Function: set_current_bank = %1\n", (int) bank));
116                 }
117                 break;
118
119         case TransportStop:
120                 _ui->transport_stop ();
121                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: transport_stop\n");
122                 break;
123
124         case TransportRoll:
125                 _ui->transport_play ();
126                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: transport_play\n");
127                 break;
128
129         case TransportStart:
130                 _ui->goto_start ();
131                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: goto_start\n");
132                 break;
133
134         case TransportZero:
135                 // need this in BasicUI
136                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: goto_zero-not implemented\n");
137                 break;
138
139         case TransportEnd:
140                 _ui->goto_end ();
141                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: goto_end\n");
142                 break;
143
144         case TransportLoopToggle:
145                 _ui->loop_toggle ();
146                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: loop_toggle\n");
147                 break;
148
149         case TransportRecordEnable:
150                 _ui->set_record_enable (true);
151                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: set_record_enable = true\n");
152                 break;
153
154         case TransportRecordDisable:
155                 _ui->set_record_enable (false);
156                 DEBUG_TRACE (DEBUG::GenericMidi, "Function: set_record_enable = false\n");
157                 break;
158
159         case Select:
160                 if (!_argument.empty()) {
161                         uint32_t rid;
162                         sscanf (_argument.c_str(), "%d", &rid);
163                         _ui->SetRouteSelection (rid);
164                         DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Function: SetRouteSelection = %1\n", rid));
165                 }
166                 break;
167         case TrackSetMute:
168                 break;
169         case TrackSetSolo:
170                 break;
171         case TrackSetSoloIsolate:
172                 break;
173         case TrackSetGain:
174                 break;
175         case TrackSetRecordEnable:
176                 break;
177         default:
178                 break;
179         }
180 }
181
182 XMLNode&
183 MIDIFunction::get_state ()
184 {
185
186         XMLNode* node = new XMLNode ("MIDIFunction");
187         return *node;
188 }
189
190 int
191 MIDIFunction::set_state (const XMLNode& /*node*/, int /*version*/)
192 {
193         return 0;
194 }
195