Dummy: add a CC only test-sequence
[ardour.git] / libs / backends / portaudio / winmmemidi_io.h
1 /*
2  * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
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 #ifndef WINMME_MIDI_IO_H
20 #define WINMME_MIDI_IO_H
21
22 #include <map>
23 #include <vector>
24 #include <string>
25 #include <stdint.h>
26 #include <pthread.h>
27
28 #include <boost/shared_ptr.hpp>
29 #include "pbd/ringbuffer.h"
30
31 #include "winmmemidi_input_device.h"
32 #include "winmmemidi_output_device.h"
33
34 namespace ARDOUR {
35
36 struct WinMMEMIDIPacket {
37
38 #if 0
39         WinMMEMIDIPacket (const WinMMEMIDIPacket& other)
40             : timeStamp (other.timeStamp)
41             , length (other.length)
42         {
43                 if (length > 0) {
44                         memcpy (data, other.data, length);
45                 }
46         }
47 #endif
48
49         // MIDITimeStamp timeStamp;
50         uint16_t length;
51         uint8_t data[256];
52 };
53
54 typedef std::vector<boost::shared_ptr<WinMMEMIDIPacket> > WinMMEMIDIQueue;
55
56 class WinMMEMidiIO {
57 public:
58         WinMMEMidiIO ();
59         ~WinMMEMidiIO ();
60
61         void start ();
62         void stop ();
63
64         bool dequeue_input_event (uint32_t port,
65                                   uint64_t timestamp_start,
66                                   uint64_t timestamp_end,
67                                   uint64_t& timestamp,
68                                   uint8_t* data,
69                                   size_t& size);
70
71         bool enqueue_output_event (uint32_t port,
72                                    uint64_t timestamp,
73                                    const uint8_t* data,
74                                    const size_t size);
75
76         uint32_t n_midi_inputs (void) const { return m_inputs.size(); }
77         uint32_t n_midi_outputs (void) const { return m_outputs.size(); }
78
79         std::vector<WinMMEMidiInputDevice*> get_inputs () { return m_inputs; }
80         std::vector<WinMMEMidiOutputDevice*> get_outputs () { return m_outputs; }
81
82         std::string port_id (uint32_t, bool input);
83         std::string port_name (uint32_t, bool input);
84
85         void set_enabled (bool yn = true) { m_enabled = yn; }
86         bool enabled (void) const { return m_active && m_enabled; }
87
88         void set_port_changed_callback (void (changed_callback (void*)), void *arg) {
89                 m_changed_callback = changed_callback;
90                 m_changed_arg = arg;
91         }
92
93 private: // Methods
94         void discover ();
95         void cleanup ();
96
97         void create_input_devices ();
98         void create_output_devices ();
99
100         void destroy_input_devices ();
101         void destroy_output_devices ();
102
103         void start_devices ();
104         void stop_devices ();
105
106 private: // Data
107
108         std::vector<WinMMEMidiInputDevice*> m_inputs;
109         std::vector<WinMMEMidiOutputDevice*> m_outputs;
110
111         bool              m_active;
112         bool              m_enabled;
113         bool              m_run;
114
115         void (* m_changed_callback) (void*);
116         void  * m_changed_arg;
117
118         // protects access to m_inputs and m_outputs
119         pthread_mutex_t m_device_lock;
120 };
121
122 } // namespace
123
124 #endif // WINMME_MIDI_IO_H
125