tweak search path for export profiles
[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 using namespace MIDI;
27
28 MIDIFunction::MIDIFunction (MIDI::Port& p)
29         : MIDIInvokable (p)
30 {
31 }
32
33 MIDIFunction::~MIDIFunction ()
34 {
35 }
36
37 int
38 MIDIFunction::init (GenericMidiControlProtocol& ui, const std::string& invokable_name, MIDI::byte* msg_data, size_t data_sz)
39 {
40         MIDIInvokable::init (ui, invokable_name, msg_data, data_sz);
41
42         if (strcasecmp (_invokable_name.c_str(), "transport-stop") == 0) {
43                 _function = TransportStop;
44         } else if (strcasecmp (_invokable_name.c_str(), "transport-roll") == 0) {
45                 _function = TransportRoll;
46         } else if (strcasecmp (_invokable_name.c_str(), "transport-zero") == 0) {
47                 _function = TransportZero;
48         } else if (strcasecmp (_invokable_name.c_str(), "transport-start") == 0) {
49                 _function = TransportStart;
50         } else if (strcasecmp (_invokable_name.c_str(), "transport-end") == 0) {
51                 _function = TransportEnd;
52         } else if (strcasecmp (_invokable_name.c_str(), "loop-toggle") == 0) {
53                 _function = TransportLoopToggle;
54         } else if (strcasecmp (_invokable_name.c_str(), "rec-enable") == 0) {
55                 _function = TransportRecordEnable;
56         } else if (strcasecmp (_invokable_name.c_str(), "rec-disable") == 0) {
57                 _function = TransportRecordDisable;
58         } else if (strcasecmp (_invokable_name.c_str(), "next-bank") == 0) {
59                 _function = NextBank;
60         } else if (strcasecmp (_invokable_name.c_str(), "prev-bank") == 0) {
61                 _function = PrevBank;
62         } else {
63                 return -1;
64         }
65
66         return 0;
67 }
68
69 void
70 MIDIFunction::execute ()
71 {
72         switch (_function) {
73         case NextBank:
74                 _ui->next_bank();
75                 break;
76
77         case PrevBank:
78                 _ui->prev_bank();
79                 break;
80
81         case TransportStop:
82                 _ui->transport_stop ();
83                 break;
84
85         case TransportRoll:
86                 _ui->transport_play ();
87                 break;
88
89         case TransportStart:
90                 _ui->goto_start ();
91                 break;
92
93         case TransportZero:
94                 // need this in BasicUI
95                 break;
96
97         case TransportEnd:
98                 _ui->goto_end ();
99                 break;
100
101         case TransportLoopToggle:
102                 _ui->loop_toggle ();
103                 break;
104
105         case TransportRecordEnable:
106                 _ui->set_record_enable (true);
107                 break;
108
109         case TransportRecordDisable:
110                 _ui->set_record_enable (false);
111                 break;
112         }
113 }
114
115 XMLNode&
116 MIDIFunction::get_state ()
117 {
118         XMLNode* node = new XMLNode ("MIDIFunction");
119         return *node;
120 }
121
122 int
123 MIDIFunction::set_state (const XMLNode& /*node*/, int /*version*/)
124 {
125         return 0;
126 }
127