new audio engine backend for native CoreAudio audio I/O, and PortMIDI for MIDI.
[ardour.git] / libs / backends / wavesaudio / waves_midiport.cc
1 /*\r
2     Copyright (C) 2014 Waves Audio Ltd.\r
3 \r
4     This program is free software; you can redistribute it and/or modify\r
5     it under the terms of the GNU General Public License as published by\r
6     the Free Software Foundation; either version 2 of the License, or\r
7     (at your option) any later version.\r
8 \r
9     This program is distributed in the hope that it will be useful,\r
10     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12     GNU General Public License for more details.\r
13 \r
14     You should have received a copy of the GNU General Public License\r
15     along with this program; if not, write to the Free Software\r
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
17 \r
18 */\r
19 \r
20 #include "waves_midiport.h"\r
21 #include "waves_midi_event.h"\r
22 \r
23 using namespace ARDOUR;\r
24 \r
25 WavesMidiPort::WavesMidiPort (const std::string& port_name, PortFlags flags)\r
26     : WavesDataPort (port_name, flags)\r
27     , _midi_device (NULL)\r
28     , _waves_midi_buffer (port_name)\r
29 {       \r
30 }\r
31 \r
32 void* \r
33 WavesMidiPort::get_buffer (pframes_t nframes)\r
34 {\r
35     if (is_input ()) {\r
36                 std::vector<WavesDataPort*>::const_iterator cit = get_connections ().begin ();\r
37         if (cit != get_connections ().end ()) {\r
38                         _waves_midi_buffer.clear ();\r
39                         WavesMidiBuffer& target = _waves_midi_buffer;\r
40 \r
41                         do      {\r
42                                 /* In fact, the static casting to (const WavesMidiPort*) is not that safe.\r
43                                  * However, mixing the buffers is assumed in the time critical conditions.\r
44                                  * Base class WavesDataPort is supposed to provide enough consistentcy\r
45                                  * of the connections.\r
46                                  */\r
47                                 target += ((const WavesMidiPort*)*cit)->const_buffer ();\r
48                         }while((++cit) != get_connections ().end ());\r
49 \r
50                         std::sort (target.begin (), target.end ());\r
51                 }\r
52         }\r
53 \r
54     return &_waves_midi_buffer;\r
55 }\r
56 \r
57 void\r
58 WavesMidiPort::_wipe_buffer()\r
59 {\r
60         _waves_midi_buffer.clear ();\r
61 }\r