~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/surfaces/generic_midi/midifunction.cc

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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::setup (GenericMidiControlProtocol& ui, const std::string& invokable_name, const std::string& arg, MIDI::byte* msg_data, size_t data_sz)
 
39
{
 
40
        MIDIInvokable::init (ui, invokable_name, msg_data, data_sz);
 
41
 
 
42
        _argument = arg;
 
43
 
 
44
        if (strcasecmp (_invokable_name.c_str(), "transport-stop") == 0) {
 
45
                _function = TransportStop;
 
46
        } else if (strcasecmp (_invokable_name.c_str(), "transport-roll") == 0) {
 
47
                _function = TransportRoll;
 
48
        } else if (strcasecmp (_invokable_name.c_str(), "transport-zero") == 0) {
 
49
                _function = TransportZero;
 
50
        } else if (strcasecmp (_invokable_name.c_str(), "transport-start") == 0) {
 
51
                _function = TransportStart;
 
52
        } else if (strcasecmp (_invokable_name.c_str(), "transport-end") == 0) {
 
53
                _function = TransportEnd;
 
54
        } else if (strcasecmp (_invokable_name.c_str(), "loop-toggle") == 0) {
 
55
                _function = TransportLoopToggle;
 
56
        } else if (strcasecmp (_invokable_name.c_str(), "rec-enable") == 0) {
 
57
                _function = TransportRecordEnable;
 
58
        } else if (strcasecmp (_invokable_name.c_str(), "rec-disable") == 0) {
 
59
                _function = TransportRecordDisable;
 
60
        } else if (strcasecmp (_invokable_name.c_str(), "next-bank") == 0) {
 
61
                _function = NextBank;
 
62
        } else if (strcasecmp (_invokable_name.c_str(), "prev-bank") == 0) {
 
63
                _function = PrevBank;
 
64
        } else if (strcasecmp (_invokable_name.c_str(), "set-bank") == 0) {
 
65
                if (_argument.empty()) {
 
66
                        return -1;
 
67
                }
 
68
                _function = SetBank;
 
69
        } else if (strcasecmp (_invokable_name.c_str(), "select") == 0) {
 
70
                if (_argument.empty()) {
 
71
                        return -1;
 
72
                }
 
73
                _function = Select;
 
74
        } else if (strcasecmp (_invokable_name.c_str(), "track-set-solo") == 0) {
 
75
                if (_argument.empty()) {
 
76
                        return -1;
 
77
                }
 
78
                _function = TrackSetSolo;
 
79
        } else if (strcasecmp (_invokable_name.c_str(), "track-set-mute") == 0) {
 
80
                if (_argument.empty()) {
 
81
                        return -1;
 
82
                }
 
83
                _function = TrackSetMute;
 
84
        } else {
 
85
                return -1;
 
86
        }
 
87
 
 
88
        return 0;
 
89
}
 
90
 
 
91
void
 
92
MIDIFunction::execute ()
 
93
{
 
94
        switch (_function) {
 
95
        case NextBank:
 
96
                _ui->next_bank();
 
97
                break;
 
98
 
 
99
        case PrevBank:
 
100
                _ui->prev_bank();
 
101
                break;
 
102
 
 
103
        case SetBank:
 
104
                if (!_argument.empty()) {
 
105
                        uint32_t bank;
 
106
                        sscanf (_argument.c_str(), "%d", &bank);
 
107
                        _ui->set_current_bank (bank);
 
108
                }
 
109
                break;
 
110
 
 
111
        case TransportStop:
 
112
                _ui->transport_stop ();
 
113
                break;
 
114
 
 
115
        case TransportRoll:
 
116
                _ui->transport_play ();
 
117
                break;
 
118
 
 
119
        case TransportStart:
 
120
                _ui->goto_start ();
 
121
                break;
 
122
 
 
123
        case TransportZero:
 
124
                // need this in BasicUI
 
125
                break;
 
126
 
 
127
        case TransportEnd:
 
128
                _ui->goto_end ();
 
129
                break;
 
130
 
 
131
        case TransportLoopToggle:
 
132
                _ui->loop_toggle ();
 
133
                break;
 
134
 
 
135
        case TransportRecordEnable:
 
136
                _ui->set_record_enable (true);
 
137
                break;
 
138
 
 
139
        case TransportRecordDisable:
 
140
                _ui->set_record_enable (false);
 
141
                break;
 
142
 
 
143
        case Select:
 
144
                if (!_argument.empty()) {
 
145
                        uint32_t rid;
 
146
                        sscanf (_argument.c_str(), "%d", &rid);
 
147
                        _ui->SetRouteSelection (rid);
 
148
                }
 
149
                break;
 
150
        case TrackSetMute:
 
151
                break;
 
152
        case TrackSetSolo:
 
153
                break;
 
154
        case TrackSetSoloIsolate:
 
155
                break;
 
156
        case TrackSetGain:
 
157
                break;
 
158
        case TrackSetRecordEnable:
 
159
                break;
 
160
        default:
 
161
                break;
 
162
        }
 
163
}
 
164
 
 
165
XMLNode&
 
166
MIDIFunction::get_state ()
 
167
{
 
168
        XMLNode* node = new XMLNode ("MIDIFunction");
 
169
        return *node;
 
170
}
 
171
 
 
172
int
 
173
MIDIFunction::set_state (const XMLNode& /*node*/, int /*version*/)
 
174
{
 
175
        return 0;
 
176
}
 
177