Merged with trunk R1283.
[ardour.git] / libs / surfaces / generic_midi / midicontrollable.h
1 /*
2     Copyright (C) 1998-2006 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     $Id: controllable.h 4 2005-05-13 20:47:18Z taybin $
19 */
20
21 #ifndef __gm_midicontrollable_h__
22 #define __gm_midicontrollable_h__
23
24 #include <string>
25
26 #include <sigc++/sigc++.h>
27
28 #include <midi++/types.h>
29 #include <pbd/controllable.h>
30 #include <pbd/stateful.h>
31 #include <ardour/types.h>
32
33 namespace MIDI {
34
35 class Channel;
36 class Port;
37 class Parser;
38
39 }
40
41 class MIDIControllable : public Stateful
42 {
43   public:
44         MIDIControllable (MIDI::Port&, PBD::Controllable&, bool bistate = false);
45         virtual ~MIDIControllable ();
46
47         void send_feedback ();
48         MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, bool force = false);
49         
50         void midi_rebind (MIDI::channel_t channel=-1);
51         void midi_forget ();
52         void learn_about_external_control ();
53         void stop_learning ();
54         void drop_external_control ();
55
56         bool get_midi_feedback () { return feedback; }
57         void set_midi_feedback (bool val) { feedback = val; }
58
59         MIDI::Port& get_port() const { return _port; }
60         PBD::Controllable& get_controllable() const { return controllable; }
61
62         std::string control_description() const { return _control_description; }
63
64         XMLNode& get_state (void);
65         int set_state (const XMLNode&);
66
67   private:
68         PBD::Controllable& controllable;
69         MIDI::Port&     _port;
70         bool             setting;
71         MIDI::byte       last_written;
72         bool             bistate;
73         int              midi_msg_id;      /* controller ID or note number */
74         sigc::connection midi_sense_connection[2];
75         sigc::connection midi_learn_connection;
76         size_t           connections;
77         MIDI::eventType  control_type;
78         MIDI::byte       control_additional;
79         MIDI::channel_t  control_channel;
80         std::string     _control_description;
81         bool             feedback;
82         
83         void midi_receiver (MIDI::Parser &p, MIDI::byte *, size_t);
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_pitchbend (MIDI::Parser &, MIDI::pitchbend_t);
90
91         void bind_midi (MIDI::channel_t, MIDI::eventType, MIDI::byte);
92 };
93
94 #endif // __gm_midicontrollable_h__
95