Ardour  8.12
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 
30 #include <boost/scoped_ptr.hpp>
31 
32 #include <pbd/ringbuffer.h>
33 
34 #define MaxWinMidiEventSize 256
35 
36 namespace ARDOUR {
37 
39 public:
41 
43 
44  bool enqueue_midi_event (uint64_t rel_event_time_us,
45  const uint8_t* data,
46  const size_t size);
47 
48  bool start ();
49  bool stop ();
50 
51  void set_enabled (bool enable);
52  bool get_enabled ();
53 
54  std::string name () const { return m_name; }
55 
56 private: // Methods
57  bool open (UINT index, std::string& error_msg);
58  bool close (std::string& error_msg);
59 
60  bool set_device_name (UINT index);
61 
62  std::string get_error_string (MMRESULT error_code);
63 
66 
67  bool signal (HANDLE semaphore);
68  bool wait (HANDLE semaphore);
69 
70  static void* midi_output_thread (void*);
72 
73  bool wait_for_microseconds (int64_t us);
74 
75  static void CALLBACK winmm_output_callback (HMIDIOUT handle,
76  UINT msg,
77  DWORD_PTR instance,
78  DWORD_PTR midi_data,
79  DWORD_PTR timestamp);
80 
81  void midi_output_callback (UINT msg, DWORD_PTR data, DWORD_PTR timestamp);
82 
83 private: // Data
84  HMIDIOUT m_handle;
85 
88 
89  HANDLE m_timer;
90 
91  bool m_started;
92  bool m_enabled;
93 
94  std::string m_name;
95 
97 
100 
101  boost::scoped_ptr<PBD::RingBuffer<uint8_t> > m_midi_buffer;
102 };
103 
104 } // namespace ARDOUR
105 
106 #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)
boost::scoped_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)