Ardour  9.0-pre0-582-g084a23a80d
winmmemidi_output_device.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef WINMME_MIDI_OUTPUT_DEVICE_H
20 #define WINMME_MIDI_OUTPUT_DEVICE_H
21 
22 #include <windows.h>
23 #include <mmsystem.h>
24 
25 #include <stdint.h>
26 #include <pthread.h>
27 
28 #include <string>
29 #include <memory>
30 
31 #include <pbd/ringbuffer.h>
32 
33 #define MaxWinMidiEventSize 256
34 
35 namespace ARDOUR {
36 
38 public:
40 
42 
43  bool enqueue_midi_event (uint64_t rel_event_time_us,
44  const uint8_t* data,
45  const size_t size);
46 
47  bool start ();
48  bool stop ();
49 
50  void set_enabled (bool enable);
51  bool get_enabled ();
52 
53  std::string name () const { return m_name; }
54 
55 private: // Methods
56  bool open (UINT index, std::string& error_msg);
57  bool close (std::string& error_msg);
58 
59  bool set_device_name (UINT index);
60 
61  std::string get_error_string (MMRESULT error_code);
62 
65 
66  bool signal (HANDLE semaphore);
67  bool wait (HANDLE semaphore);
68 
69  static void* midi_output_thread (void*);
71 
72  bool wait_for_microseconds (int64_t us);
73 
74  static void CALLBACK winmm_output_callback (HMIDIOUT handle,
75  UINT msg,
76  DWORD_PTR instance,
77  DWORD_PTR midi_data,
78  DWORD_PTR timestamp);
79 
80  void midi_output_callback (UINT msg, DWORD_PTR data, DWORD_PTR timestamp);
81 
82 private: // Data
83  HMIDIOUT m_handle;
84 
87 
88  HANDLE m_timer;
89 
90  bool m_started;
91  bool m_enabled;
92 
93  std::string m_name;
94 
96 
99 
100  const std::unique_ptr<PBD::RingBuffer<uint8_t> > m_midi_buffer;
101 };
102 
103 } // namespace ARDOUR
104 
105 #endif // WINMME_MIDI_OUTPUT_DEVICE_H
static void CALLBACK winmm_output_callback(HMIDIOUT handle, UINT msg, DWORD_PTR instance, DWORD_PTR midi_data, DWORD_PTR timestamp)
std::string get_error_string(MMRESULT error_code)
bool signal(HANDLE semaphore)
const std::unique_ptr< PBD::RingBuffer< uint8_t > > m_midi_buffer
bool close(std::string &error_msg)
bool enqueue_midi_event(uint64_t rel_event_time_us, const uint8_t *data, const size_t size)
void set_enabled(bool enable)
static void * midi_output_thread(void *)
bool wait_for_microseconds(int64_t us)
bool set_device_name(UINT index)
bool open(UINT index, std::string &error_msg)
bool wait(HANDLE semaphore)
void midi_output_callback(UINT msg, DWORD_PTR data, DWORD_PTR timestamp)