3fa108bb4692590fc5a4da74baa185ea2dc9b8f0
[ardour.git] / libs / midi++2 / midi++ / controllable.h
1 /*
2     Copyright (C) 1998-99 Paul Barton-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$
19 */
20
21 #ifndef __qm_midicontrollable_h__
22 #define __qm_midicontrollable_h__
23
24 #include <string>
25
26 #include <sigc++/sigc++.h>
27
28 #include <midi++/types.h>
29
30 namespace MIDI {
31
32 class Channel;
33 class Port;
34 class Parser;
35
36 class Controllable : public sigc::trackable
37 {
38   public:
39         Controllable (Port *, bool bistate = false);
40         virtual ~Controllable ();
41
42         void midi_rebind (Port *, channel_t channel=-1);
43         void midi_forget ();
44         void learn_about_external_control ();
45         void stop_learning ();
46         void drop_external_control ();
47
48         virtual void set_value (float) = 0;
49
50         sigc::signal<void> learning_started;
51         sigc::signal<void> learning_stopped;
52
53         bool get_control_info (channel_t&, eventType&, byte&);
54         void set_control_type (channel_t, eventType, byte);
55
56         bool get_midi_feedback () { return feedback; }
57         void set_midi_feedback (bool val) { feedback = val; }
58
59         Port * get_port() { return port; }
60         
61         std::string control_description() const { return _control_description; }
62
63         void send_midi_feedback (float);
64         
65   private:
66         bool             bistate;
67         int              midi_msg_id;      /* controller ID or note number */
68         sigc::connection midi_sense_connection[2];
69         sigc::connection midi_learn_connection;
70         size_t           connections;
71         Port*            port;
72         eventType        control_type;
73         byte             control_additional;
74         channel_t        control_channel;
75         std::string     _control_description;
76         bool             feedback;
77         
78         void midi_receiver (Parser &p, byte *, size_t);
79         void midi_sense_note (Parser &, EventTwoBytes *, bool is_on);
80         void midi_sense_note_on (Parser &p, EventTwoBytes *tb);
81         void midi_sense_note_off (Parser &p, EventTwoBytes *tb);
82         void midi_sense_controller (Parser &, EventTwoBytes *);
83         void midi_sense_program_change (Parser &, byte);
84         void midi_sense_pitchbend (Parser &, pitchbend_t);
85
86         void bind_midi (channel_t, eventType, byte);
87 };
88
89 }; /* namespace MIDI */
90
91 #endif // __qm_midicontrollable_h__
92