Ardour  9.0-pre0-582-g084a23a80d
winmmemidi_io.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef WINMME_MIDI_IO_H
21 #define WINMME_MIDI_IO_H
22 
23 #include <map>
24 #include <memory>
25 #include <vector>
26 #include <string>
27 #include <stdint.h>
28 #include <pthread.h>
29 
30 #include "pbd/ringbuffer.h"
31 
34 
35 #include "midi_device_info.h"
36 
37 namespace ARDOUR {
38 
40 
41 #if 0
42  WinMMEMIDIPacket (const WinMMEMIDIPacket& other)
43  : timeStamp (other.timeStamp)
44  , length (other.length)
45  {
46  if (length > 0) {
47  memcpy (data, other.data, length);
48  }
49  }
50 #endif
51 
52  // MIDITimeStamp timeStamp;
53  uint16_t length;
55 };
56 
57 typedef std::vector<std::shared_ptr<WinMMEMIDIPacket> > WinMMEMIDIQueue;
58 
59 class WinMMEMidiIO {
60 public:
63 
64  void start ();
65  void stop ();
66 
67  bool dequeue_input_event (uint32_t port,
68  uint64_t timestamp_start,
69  uint64_t timestamp_end,
70  uint64_t& timestamp,
71  uint8_t* data,
72  size_t& size);
73 
74  bool enqueue_output_event (uint32_t port,
75  uint64_t timestamp,
76  const uint8_t* data,
77  const size_t size);
78 
79  uint32_t n_midi_inputs (void) const { return m_inputs.size(); }
80  uint32_t n_midi_outputs (void) const { return m_outputs.size(); }
81 
82  std::vector<WinMMEMidiInputDevice*> get_inputs () { return m_inputs; }
83  std::vector<WinMMEMidiOutputDevice*> get_outputs () { return m_outputs; }
84 
86 
87  std::vector<MidiDeviceInfo*> get_device_info () { return m_device_info; }
88 
89  MidiDeviceInfo* get_device_info (const std::string& name);
90 
91  std::string port_id (uint32_t, bool input);
92  std::string port_name (uint32_t, bool input);
93 
94  void set_enabled (bool yn = true) { m_enabled = yn; }
95  bool enabled (void) const { return m_active && m_enabled; }
96 
97  void set_port_changed_callback (void (changed_callback (void*)), void *arg) {
98  m_changed_callback = changed_callback;
99  m_changed_arg = arg;
100  }
101 
102 private: // Methods
103 
105 
106  static bool get_input_name_from_index (int index, std::string& name);
107  static bool get_output_name_from_index (int index, std::string& name);
108 
109  void discover ();
110  void cleanup ();
111 
114 
117 
118  void start_devices ();
119  void stop_devices ();
120 
121 private: // Data
122 
123  std::vector<MidiDeviceInfo*> m_device_info;
124 
125  std::vector<WinMMEMidiInputDevice*> m_inputs;
126  std::vector<WinMMEMidiOutputDevice*> m_outputs;
127 
128  bool m_active;
129  bool m_enabled;
130  bool m_run;
131 
132  void (* m_changed_callback) (void*);
134 
135  // protects access to m_inputs and m_outputs
136  pthread_mutex_t m_device_lock;
137 };
138 
139 } // namespace
140 
141 #endif // WINMME_MIDI_IO_H
142 
std::string port_id(uint32_t, bool input)
static bool get_input_name_from_index(int index, std::string &name)
MidiDeviceInfo * get_device_info(const std::string &name)
uint32_t n_midi_outputs(void) const
Definition: winmmemidi_io.h:80
bool enabled(void) const
Definition: winmmemidi_io.h:95
static bool get_output_name_from_index(int index, std::string &name)
pthread_mutex_t m_device_lock
bool dequeue_input_event(uint32_t port, uint64_t timestamp_start, uint64_t timestamp_end, uint64_t &timestamp, uint8_t *data, size_t &size)
bool enqueue_output_event(uint32_t port, uint64_t timestamp, const uint8_t *data, const size_t size)
uint32_t n_midi_inputs(void) const
Definition: winmmemidi_io.h:79
void set_port_changed_callback(void(changed_callback(void *)), void *arg)
Definition: winmmemidi_io.h:97
std::vector< WinMMEMidiOutputDevice * > m_outputs
void set_enabled(bool yn=true)
Definition: winmmemidi_io.h:94
std::vector< WinMMEMidiOutputDevice * > get_outputs()
Definition: winmmemidi_io.h:83
std::vector< MidiDeviceInfo * > get_device_info()
Definition: winmmemidi_io.h:87
std::vector< MidiDeviceInfo * > m_device_info
std::string port_name(uint32_t, bool input)
std::vector< WinMMEMidiInputDevice * > m_inputs
void(* m_changed_callback)(void *)
std::vector< WinMMEMidiInputDevice * > get_inputs()
Definition: winmmemidi_io.h:82
GtkImageIconNameData name
Definition: gtkimage.h:6
std::vector< std::shared_ptr< WinMMEMIDIPacket > > WinMMEMIDIQueue
Definition: winmmemidi_io.h:57
#define MaxWinMidiEventSize