Debian Codegraph @

macosx/coremidi/JackCoreMidiPhysicalOutputPort.mm

raw
1 /*
2 Copyright (C) 2011 Devin Anderson
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
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <sstream>
21 #include <stdexcept>
22
23 #include "JackCoreMidiPhysicalOutputPort.h"
24 #include "JackCoreMidiUtil.h"
25
26 using Jack::JackCoreMidiPhysicalOutputPort;
27
28 JackCoreMidiPhysicalOutputPort::
29 JackCoreMidiPhysicalOutputPort(const char *alias_name, const char *client_name,
30 const char *driver_name, int index,
31 MIDIClientRef client,
32 MIDIPortRef internal_output, double time_ratio,
33 size_t max_bytes,
34 size_t max_messages):
35 JackCoreMidiOutputPort(time_ratio, max_bytes,
36 max_messages)
37 {
38 MIDIEndpointRef destination = MIDIGetDestination(index);
39 if (! destination) {
40 // X: Can we get a better error message?
41 std::stringstream stream;
42 stream << "The destination at index '" << index
43 << "' is not available";
44 throw std::runtime_error(stream.str().c_str());
45 }
46 SInt32 advance_schedule_time;
47 OSStatus status =
48 MIDIObjectGetIntegerProperty(destination,
49 kMIDIPropertyAdvanceScheduleTimeMuSec,
50 &advance_schedule_time);
51 if (status != noErr) {
52 WriteMacOSError("JackCoreMidiPhysicalOutputPort [constructor]",
53 "MIDIObjectGetIntegerProperty", status);
54 advance_schedule_time = 0;
55 } else if (advance_schedule_time < 0) {
56 advance_schedule_time = 0;
57 }
58 Initialize(alias_name, client_name, driver_name, index, destination,
59 advance_schedule_time);
60 this->internal_output = internal_output;
61 }
62
63 JackCoreMidiPhysicalOutputPort::~JackCoreMidiPhysicalOutputPort()
64 {
65 // Empty
66 }
67
68 bool
69 JackCoreMidiPhysicalOutputPort::SendPacketList(MIDIPacketList *packet_list)
70 {
71 OSStatus status = MIDISend(internal_output, endpoint, packet_list);
72 bool result = status == noErr;
73 if (! result) {
74 WriteMacOSError("JackCoreMidiPhysicalOutputPort::SendPacketList",
75 "MIDISend", status);
76 }
77 return result;
78 }