Ardour  9.0-pre0-582-g084a23a80d
winmmemidi_input_device.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_INPUT_DEVICE_H
21 #define WINMME_MIDI_INPUT_DEVICE_H
22 
23 #include <windows.h>
24 #include <mmsystem.h>
25 
26 #include <stdint.h>
27 
28 #include <string>
29 #include <memory>
30 
31 #include <pbd/ringbuffer.h>
32 
33 namespace ARDOUR {
34 
36 public: // ctors
37  WinMMEMidiInputDevice (int index);
38 
40 
41 public: // methods
42 
49  bool dequeue_midi_event (uint64_t timestamp_start,
50  uint64_t timestamp_end,
51  uint64_t& timestamp,
52  uint8_t* data,
53  size_t& size);
54 
55  bool start ();
56  bool stop ();
57 
58  void set_enabled (bool enable);
59 
60  bool get_enabled ();
61 
65  std::string name () const { return m_name; }
66 
67 private: // methods
68  bool open (UINT index, std::string& error_msg);
69  bool close (std::string& error_msg);
70 
71  bool add_sysex_buffer (std::string& error_msg);
72  bool set_device_name (UINT index);
73 
74  std::string get_error_string (MMRESULT error_code);
75 
76  static void CALLBACK winmm_input_callback (HMIDIIN handle,
77  UINT msg,
78  DWORD_PTR instance,
79  DWORD_PTR midi_msg,
80  DWORD timestamp);
81 
82  void handle_short_msg (const uint8_t* midi_data, uint32_t timestamp);
83 
84  void handle_sysex_msg (MIDIHDR* const midi_header, uint32_t timestamp);
85 
86  bool enqueue_midi_msg (const uint8_t* midi_data, size_t size, uint32_t timestamp);
87 
88 private: // data
89  HMIDIIN m_handle;
90  MIDIHDR m_sysex_header;
91 
92  bool m_started;
93 
94  std::string m_name;
95 
96  // can't use unique_ptr yet
97  const std::unique_ptr<PBD::RingBuffer<uint8_t> > m_midi_buffer;
98  std::unique_ptr<uint8_t[]> m_sysex_buffer;
99 };
100 
101 }
102 
103 #endif // WINMME_MIDI_INPUT_DEVICE_H
void set_enabled(bool enable)
bool open(UINT index, std::string &error_msg)
const std::unique_ptr< PBD::RingBuffer< uint8_t > > m_midi_buffer
bool dequeue_midi_event(uint64_t timestamp_start, uint64_t timestamp_end, uint64_t &timestamp, uint8_t *data, size_t &size)
std::string get_error_string(MMRESULT error_code)
bool close(std::string &error_msg)
bool add_sysex_buffer(std::string &error_msg)
bool set_device_name(UINT index)
void handle_short_msg(const uint8_t *midi_data, uint32_t timestamp)
void handle_sysex_msg(MIDIHDR *const midi_header, uint32_t timestamp)
static void CALLBACK winmm_input_callback(HMIDIIN handle, UINT msg, DWORD_PTR instance, DWORD_PTR midi_msg, DWORD timestamp)
std::unique_ptr< uint8_t[]> m_sysex_buffer
bool enqueue_midi_msg(const uint8_t *midi_data, size_t size, uint32_t timestamp)