bc019cfb3c24721b1b4799c03f1158f55ddb704b
[ardour.git] / libs / surfaces / generic_midi / midifunction.h
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
20 #ifndef __gm_midifunction_h__
21 #define __gm_midifunction_h__
22
23 #include <string>
24
25 #include "midi++/types.h"
26
27 #include "pbd/signals.h"
28 #include "pbd/stateful.h"
29
30 #include "ardour/types.h"
31
32 namespace MIDI {
33         class Channel;
34         class Port;
35         class Parser;
36 }
37
38 class GenericMidiControlProtocol;
39
40 class MIDIFunction : public PBD::Stateful
41 {
42   public:
43         enum Function { 
44                 NextBank,
45                 PrevBank,
46                 TransportRoll,
47                 TransportStop,
48                 TransportZero,
49                 TransportStart,
50                 TransportEnd,
51                 TransportLoopToggle,
52                 TransportRecordEnable,
53                 TransportRecordDisable
54         };
55
56         MIDIFunction (MIDI::Port&);
57         virtual ~MIDIFunction ();
58
59         int init (GenericMidiControlProtocol&, const std::string& function_name, MIDI::byte* sysex = 0, size_t ssize = 0);
60
61         MIDI::Port& get_port() const { return _port; }
62         const std::string& function_name() const { return _function_name; }
63
64         XMLNode& get_state (void);
65         int set_state (const XMLNode&, int version);
66
67         void bind_midi (MIDI::channel_t, MIDI::eventType, MIDI::byte);
68         MIDI::channel_t get_control_channel () { return control_channel; }
69         MIDI::eventType get_control_type () { return control_type; }
70         MIDI::byte get_control_additional () { return control_additional; }
71         
72   private:
73         Function        _function;
74         GenericMidiControlProtocol* _ui;
75         std::string     _function_name;
76         MIDI::Port&     _port;
77         PBD::ScopedConnection midi_sense_connection[2];
78         MIDI::eventType  control_type;
79         MIDI::byte       control_additional;
80         MIDI::channel_t  control_channel;
81         MIDI::byte*      sysex;
82         size_t         sysex_size;
83
84         void execute ();
85
86         void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on);
87         void midi_sense_note_on (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
88         void midi_sense_note_off (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
89         void midi_sense_controller (MIDI::Parser &, MIDI::EventTwoBytes *);
90         void midi_sense_program_change (MIDI::Parser &, MIDI::byte);
91         void midi_sense_sysex (MIDI::Parser &, MIDI::byte*, size_t);
92 };
93
94 #endif // __gm_midicontrollable_h__
95