add sysex support to MIDI binding maps, and a couple more functions
[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 BasicUI;
39
40 class MIDIFunction : public PBD::Stateful
41 {
42   public:
43         enum Function { 
44                 TransportRoll,
45                 TransportStop,
46                 TransportZero,
47                 TransportStart,
48                 TransportEnd,
49                 TransportLoopToggle,
50                 TransportRecordEnable,
51                 TransportRecordDisable
52         };
53
54         MIDIFunction (MIDI::Port&);
55         virtual ~MIDIFunction ();
56
57         int init (BasicUI&, const std::string& function_name, MIDI::byte* sysex = 0, size_t ssize = 0);
58
59         MIDI::Port& get_port() const { return _port; }
60         const std::string& function_name() const { return _function_name; }
61
62         XMLNode& get_state (void);
63         int set_state (const XMLNode&, int version);
64
65         void bind_midi (MIDI::channel_t, MIDI::eventType, MIDI::byte);
66         MIDI::channel_t get_control_channel () { return control_channel; }
67         MIDI::eventType get_control_type () { return control_type; }
68         MIDI::byte get_control_additional () { return control_additional; }
69         
70   private:
71         Function        _function;
72         BasicUI*        _ui;
73         std::string     _function_name;
74         MIDI::Port&     _port;
75         PBD::ScopedConnection midi_sense_connection[2];
76         MIDI::eventType  control_type;
77         MIDI::byte       control_additional;
78         MIDI::channel_t  control_channel;
79         MIDI::byte*      sysex;
80         size_t         sysex_size;
81
82         void execute ();
83
84         void midi_sense_note (MIDI::Parser &, MIDI::EventTwoBytes *, bool is_on);
85         void midi_sense_note_on (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
86         void midi_sense_note_off (MIDI::Parser &p, MIDI::EventTwoBytes *tb);
87         void midi_sense_controller (MIDI::Parser &, MIDI::EventTwoBytes *);
88         void midi_sense_program_change (MIDI::Parser &, MIDI::byte);
89         void midi_sense_sysex (MIDI::Parser &, MIDI::byte*, size_t);
90 };
91
92 #endif // __gm_midicontrollable_h__
93