Ardour  8.12
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 
30 #include <boost/scoped_array.hpp>
31 #include <boost/scoped_ptr.hpp>
32 
33 #include <pbd/ringbuffer.h>
34 
35 namespace ARDOUR {
36 
38 public: // ctors
39  WinMMEMidiInputDevice (int index);
40 
42 
43 public: // methods
44 
51  bool dequeue_midi_event (uint64_t timestamp_start,
52  uint64_t timestamp_end,
53  uint64_t& timestamp,
54  uint8_t* data,
55  size_t& size);
56 
57  bool start ();
58  bool stop ();
59 
60  void set_enabled (bool enable);
61 
62  bool get_enabled ();
63 
67  std::string name () const { return m_name; }
68 
69 private: // methods
70  bool open (UINT index, std::string& error_msg);
71  bool close (std::string& error_msg);
72 
73  bool add_sysex_buffer (std::string& error_msg);
74  bool set_device_name (UINT index);
75 
76  std::string get_error_string (MMRESULT error_code);
77 
78  static void CALLBACK winmm_input_callback (HMIDIIN handle,
79  UINT msg,
80  DWORD_PTR instance,
81  DWORD_PTR midi_msg,
82  DWORD timestamp);
83 
84  void handle_short_msg (const uint8_t* midi_data, uint32_t timestamp);
85 
86  void handle_sysex_msg (MIDIHDR* const midi_header, uint32_t timestamp);
87 
88  bool enqueue_midi_msg (const uint8_t* midi_data, size_t size, uint32_t timestamp);
89 
90 private: // data
91  HMIDIIN m_handle;
92  MIDIHDR m_sysex_header;
93 
94  bool m_started;
95 
96  std::string m_name;
97 
98  // can't use unique_ptr yet
99  boost::scoped_ptr<PBD::RingBuffer<uint8_t> > m_midi_buffer;
100  boost::scoped_array<uint8_t> m_sysex_buffer;
101 };
102 
103 }
104 
105 #endif // WINMME_MIDI_INPUT_DEVICE_H
void set_enabled(bool enable)
bool open(UINT index, std::string &error_msg)
boost::scoped_ptr< PBD::RingBuffer< uint8_t > > m_midi_buffer
boost::scoped_array< uint8_t > m_sysex_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)
bool enqueue_midi_msg(const uint8_t *midi_data, size_t size, uint32_t timestamp)