jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

703 lines
24KB

  1. /*
  2. Copyright (C) 2009 Grame
  3. Copyright (C) 2011 Devin Anderson
  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. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <stdexcept>
  17. #include <mach/mach_time.h>
  18. #include "JackCoreMidiDriver.h"
  19. #include "JackCoreMidiUtil.h"
  20. #include "JackEngineControl.h"
  21. using Jack::JackCoreMidiDriver;
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // Static callbacks
  24. ///////////////////////////////////////////////////////////////////////////////
  25. void
  26. JackCoreMidiDriver::HandleInputEvent(const MIDIPacketList *packet_list,
  27. void *driver, void *port)
  28. {
  29. ((JackCoreMidiPhysicalInputPort *) port)->ProcessCoreMidi(packet_list);
  30. }
  31. void
  32. JackCoreMidiDriver::HandleNotificationEvent(const MIDINotification *message,
  33. void *driver)
  34. {
  35. ((JackCoreMidiDriver *) driver)->HandleNotification(message);
  36. }
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // Class
  39. ///////////////////////////////////////////////////////////////////////////////
  40. JackCoreMidiDriver::JackCoreMidiDriver(const char *name, const char *alias,
  41. JackLockedEngine *engine,
  42. JackSynchro *table):
  43. JackMidiDriver(name, alias, engine, table)
  44. {
  45. mach_timebase_info_data_t info;
  46. kern_return_t result = mach_timebase_info(&info);
  47. if (result != KERN_SUCCESS) {
  48. throw std::runtime_error(mach_error_string(result));
  49. }
  50. client = 0;
  51. fCaptureChannels = 0;
  52. fPlaybackChannels = 0;
  53. num_physical_inputs = 0;
  54. num_physical_outputs = 0;
  55. num_virtual_inputs = 0;
  56. num_virtual_outputs = 0;
  57. physical_input_ports = 0;
  58. physical_output_ports = 0;
  59. time_ratio = (((double) info.numer) / info.denom) / 1000.0;
  60. virtual_input_ports = 0;
  61. virtual_output_ports = 0;
  62. }
  63. JackCoreMidiDriver::~JackCoreMidiDriver()
  64. {
  65. Stop();
  66. Close();
  67. }
  68. int
  69. JackCoreMidiDriver::Attach()
  70. {
  71. jack_nframes_t buffer_size = fEngineControl->fBufferSize;
  72. jack_port_id_t index;
  73. jack_nframes_t latency = buffer_size;
  74. jack_latency_range_t latency_range;
  75. const char *name;
  76. JackPort *port;
  77. JackCoreMidiPort *port_obj;
  78. latency_range.max = latency;
  79. latency_range.min = latency;
  80. // Physical inputs
  81. for (int i = 0; i < num_physical_inputs; i++) {
  82. port_obj = physical_input_ports[i];
  83. name = port_obj->GetName();
  84. index = fGraphManager->AllocatePort(fClientControl.fRefNum, name,
  85. JACK_DEFAULT_MIDI_TYPE,
  86. CaptureDriverFlags, buffer_size);
  87. if (index == NO_PORT) {
  88. jack_error("JackCoreMidiDriver::Attach - cannot register physical "
  89. "input port with name '%s'.", name);
  90. // X: Do we need to deallocate ports?
  91. return -1;
  92. }
  93. port = fGraphManager->GetPort(index);
  94. port->SetAlias(port_obj->GetAlias());
  95. port->SetLatencyRange(JackCaptureLatency, &latency_range);
  96. fCapturePortList[i] = index;
  97. }
  98. // Virtual inputs
  99. for (int i = 0; i < num_virtual_inputs; i++) {
  100. port_obj = virtual_input_ports[i];
  101. name = port_obj->GetName();
  102. index = fGraphManager->AllocatePort(fClientControl.fRefNum, name,
  103. JACK_DEFAULT_MIDI_TYPE,
  104. CaptureDriverFlags, buffer_size);
  105. if (index == NO_PORT) {
  106. jack_error("JackCoreMidiDriver::Attach - cannot register virtual "
  107. "input port with name '%s'.", name);
  108. // X: Do we need to deallocate ports?
  109. return -1;
  110. }
  111. port = fGraphManager->GetPort(index);
  112. port->SetAlias(port_obj->GetAlias());
  113. port->SetLatencyRange(JackCaptureLatency, &latency_range);
  114. fCapturePortList[num_physical_inputs + i] = index;
  115. }
  116. if (! fEngineControl->fSyncMode) {
  117. latency += buffer_size;
  118. latency_range.max = latency;
  119. latency_range.min = latency;
  120. }
  121. // Physical outputs
  122. for (int i = 0; i < num_physical_outputs; i++) {
  123. port_obj = physical_output_ports[i];
  124. name = port_obj->GetName();
  125. index = fGraphManager->AllocatePort(fClientControl.fRefNum, name,
  126. JACK_DEFAULT_MIDI_TYPE,
  127. PlaybackDriverFlags, buffer_size);
  128. if (index == NO_PORT) {
  129. jack_error("JackCoreMidiDriver::Attach - cannot register physical "
  130. "output port with name '%s'.", name);
  131. // X: Do we need to deallocate ports?
  132. return -1;
  133. }
  134. port = fGraphManager->GetPort(index);
  135. port->SetAlias(port_obj->GetAlias());
  136. port->SetLatencyRange(JackPlaybackLatency, &latency_range);
  137. fPlaybackPortList[i] = index;
  138. }
  139. // Virtual outputs
  140. for (int i = 0; i < num_virtual_outputs; i++) {
  141. port_obj = virtual_output_ports[i];
  142. name = port_obj->GetName();
  143. index = fGraphManager->AllocatePort(fClientControl.fRefNum, name,
  144. JACK_DEFAULT_MIDI_TYPE,
  145. PlaybackDriverFlags, buffer_size);
  146. if (index == NO_PORT) {
  147. jack_error("JackCoreMidiDriver::Attach - cannot register virtual "
  148. "output port with name '%s'.", name);
  149. // X: Do we need to deallocate ports?
  150. return -1;
  151. }
  152. port = fGraphManager->GetPort(index);
  153. port->SetAlias(port_obj->GetAlias());
  154. port->SetLatencyRange(JackPlaybackLatency, &latency_range);
  155. fPlaybackPortList[num_physical_outputs + i] = index;
  156. }
  157. return 0;
  158. }
  159. int
  160. JackCoreMidiDriver::Close()
  161. {
  162. int result = 0;
  163. OSStatus status;
  164. if (physical_input_ports) {
  165. for (int i = 0; i < num_physical_inputs; i++) {
  166. delete physical_input_ports[i];
  167. }
  168. delete[] physical_input_ports;
  169. num_physical_inputs = 0;
  170. physical_input_ports = 0;
  171. status = MIDIPortDispose(internal_input);
  172. if (status != noErr) {
  173. WriteMacOSError("JackCoreMidiDriver::Close", "MIDIPortDispose",
  174. status);
  175. result = -1;
  176. }
  177. }
  178. if (physical_output_ports) {
  179. for (int i = 0; i < num_physical_outputs; i++) {
  180. delete physical_output_ports[i];
  181. }
  182. delete[] physical_output_ports;
  183. num_physical_outputs = 0;
  184. physical_output_ports = 0;
  185. status = MIDIPortDispose(internal_output);
  186. if (status != noErr) {
  187. WriteMacOSError("JackCoreMidiDriver::Close", "MIDIPortDispose",
  188. status);
  189. result = -1;
  190. }
  191. }
  192. if (virtual_input_ports) {
  193. for (int i = 0; i < num_virtual_inputs; i++) {
  194. delete virtual_input_ports[i];
  195. }
  196. delete[] virtual_input_ports;
  197. num_virtual_inputs = 0;
  198. virtual_input_ports = 0;
  199. }
  200. if (virtual_output_ports) {
  201. for (int i = 0; i < num_virtual_outputs; i++) {
  202. delete virtual_output_ports[i];
  203. }
  204. delete[] virtual_output_ports;
  205. num_virtual_outputs = 0;
  206. virtual_output_ports = 0;
  207. }
  208. if (client) {
  209. status = MIDIClientDispose(client);
  210. if (status != noErr) {
  211. WriteMacOSError("JackCoreMidiDriver::Close", "MIDIClientDispose",
  212. status);
  213. result = -1;
  214. }
  215. client = 0;
  216. }
  217. return result;
  218. }
  219. void
  220. JackCoreMidiDriver::HandleNotification(const MIDINotification *message)
  221. {
  222. // Empty
  223. }
  224. int
  225. JackCoreMidiDriver::Open(bool capturing, bool playing, int in_channels,
  226. int out_channels, bool monitor,
  227. const char* capture_driver_name,
  228. const char* playback_driver_name,
  229. jack_nframes_t capture_latency,
  230. jack_nframes_t playback_latency)
  231. {
  232. int pi_count = 0;
  233. int po_count = 0;
  234. int vi_count = 0;
  235. int vo_count = 0;
  236. ItemCount potential_po_count;
  237. ItemCount potential_pi_count;
  238. CFStringRef name = CFStringCreateWithCString(0, "JackMidi",
  239. CFStringGetSystemEncoding());
  240. if (! name) {
  241. jack_error("JackCoreMidiDriver::Open - failed to allocate memory for "
  242. "client name string");
  243. return -1;
  244. }
  245. OSStatus status = MIDIClientCreate(name, HandleNotificationEvent, this,
  246. &client);
  247. CFRelease(name);
  248. if (status != noErr) {
  249. WriteMacOSError("JackCoreMidiDriver::Close", "MIDIClientCreate",
  250. status);
  251. return -1;
  252. }
  253. char *client_name = fClientControl.fName;
  254. // Allocate and connect physical inputs
  255. potential_pi_count = MIDIGetNumberOfSources();
  256. if (potential_pi_count) {
  257. status = MIDIInputPortCreate(client, CFSTR("Physical Input Port"),
  258. HandleInputEvent, this, &internal_input);
  259. if (status != noErr) {
  260. WriteMacOSError("JackCoreMidiDriver::Open", "MIDIInputPortCreate",
  261. status);
  262. goto destroy_virtual_output_ports;
  263. }
  264. try {
  265. physical_input_ports =
  266. new JackCoreMidiPhysicalInputPort*[potential_pi_count];
  267. } catch (std::exception e) {
  268. jack_error("JackCoreMidiDriver::Open - while creating physical "
  269. "input port array: %s", e.what());
  270. goto destroy_internal_input_port;
  271. }
  272. for (ItemCount i = 0; i < potential_pi_count; i++) {
  273. try {
  274. physical_input_ports[pi_count] =
  275. new JackCoreMidiPhysicalInputPort(fAliasName, client_name,
  276. capture_driver_name, i,
  277. client, internal_input,
  278. time_ratio);
  279. } catch (std::exception e) {
  280. jack_error("JackCoreMidiDriver::Open - while creating "
  281. "physical input port: %s", e.what());
  282. goto destroy_internal_input_port;
  283. }
  284. pi_count++;
  285. }
  286. }
  287. // Allocate and connect physical outputs
  288. potential_po_count = MIDIGetNumberOfDestinations();
  289. if (potential_po_count) {
  290. status = MIDIOutputPortCreate(client, CFSTR("Physical Output Port"),
  291. &internal_output);
  292. if (status != noErr) {
  293. WriteMacOSError("JackCoreMidiDriver::Open", "MIDIOutputPortCreate",
  294. status);
  295. goto destroy_physical_input_ports;
  296. }
  297. try {
  298. physical_output_ports =
  299. new JackCoreMidiPhysicalOutputPort*[potential_po_count];
  300. } catch (std::exception e) {
  301. jack_error("JackCoreMidiDriver::Open - while creating physical "
  302. "output port array: %s", e.what());
  303. goto destroy_internal_output_port;
  304. }
  305. for (ItemCount i = 0; i < potential_po_count; i++) {
  306. try {
  307. physical_output_ports[po_count] =
  308. new JackCoreMidiPhysicalOutputPort(fAliasName, client_name,
  309. playback_driver_name, i,
  310. client, internal_output,
  311. time_ratio);
  312. } catch (std::exception e) {
  313. jack_error("JackCoreMidiDriver::Open - while creating "
  314. "physical output port: %s", e.what());
  315. goto destroy_internal_output_port;
  316. }
  317. po_count++;
  318. }
  319. }
  320. // Allocate and connect virtual inputs
  321. if (in_channels) {
  322. try {
  323. virtual_input_ports =
  324. new JackCoreMidiVirtualInputPort*[in_channels];
  325. } catch (std::exception e) {
  326. jack_error("JackCoreMidiDriver::Open - while creating virtual "
  327. "input port array: %s", e.what());
  328. goto destroy_client;
  329. }
  330. for (vi_count = 0; vi_count < in_channels; vi_count++) {
  331. try {
  332. virtual_input_ports[vi_count] =
  333. new JackCoreMidiVirtualInputPort(fAliasName, client_name,
  334. capture_driver_name,
  335. vi_count + pi_count, client,
  336. time_ratio);
  337. } catch (std::exception e) {
  338. jack_error("JackCoreMidiDriver::Open - while creating virtual "
  339. "input port: %s", e.what());
  340. goto destroy_virtual_input_ports;
  341. }
  342. }
  343. }
  344. // Allocate and connect virtual outputs
  345. if (out_channels) {
  346. try {
  347. virtual_output_ports =
  348. new JackCoreMidiVirtualOutputPort*[out_channels];
  349. } catch (std::exception e) {
  350. jack_error("JackCoreMidiDriver::Open - while creating virtual "
  351. "output port array: %s", e.what());
  352. goto destroy_virtual_input_ports;
  353. }
  354. for (vo_count = 0; vo_count < out_channels; vo_count++) {
  355. try {
  356. virtual_output_ports[vo_count] =
  357. new JackCoreMidiVirtualOutputPort(fAliasName, client_name,
  358. playback_driver_name,
  359. vo_count + po_count, client,
  360. time_ratio);
  361. } catch (std::exception e) {
  362. jack_error("JackCoreMidiDriver::Open - while creating virtual "
  363. "output port: %s", e.what());
  364. goto destroy_virtual_output_ports;
  365. }
  366. }
  367. }
  368. if (! (pi_count || po_count || in_channels || out_channels)) {
  369. jack_error("JackCoreMidiDriver::Open - no CoreMIDI inputs or outputs "
  370. "found, and no virtual ports allocated.");
  371. } else if (! JackMidiDriver::Open(capturing, playing,
  372. in_channels + pi_count,
  373. out_channels + po_count, monitor,
  374. capture_driver_name,
  375. playback_driver_name, capture_latency,
  376. playback_latency)) {
  377. num_physical_inputs = pi_count;
  378. num_physical_outputs = po_count;
  379. num_virtual_inputs = in_channels;
  380. num_virtual_outputs = out_channels;
  381. return 0;
  382. }
  383. // Cleanup
  384. if (physical_output_ports) {
  385. for (int i = 0; i < po_count; i++) {
  386. delete physical_output_ports[i];
  387. }
  388. delete[] physical_output_ports;
  389. physical_output_ports = 0;
  390. }
  391. destroy_internal_output_port:
  392. status = MIDIPortDispose(internal_output);
  393. if (status != noErr) {
  394. WriteMacOSError("JackCoreMidiDriver::Open", "MIDIPortDispose", status);
  395. }
  396. destroy_physical_input_ports:
  397. if (physical_input_ports) {
  398. for (int i = 0; i < pi_count; i++) {
  399. delete physical_input_ports[i];
  400. }
  401. delete[] physical_input_ports;
  402. physical_input_ports = 0;
  403. }
  404. destroy_internal_input_port:
  405. status = MIDIPortDispose(internal_input);
  406. if (status != noErr) {
  407. WriteMacOSError("JackCoreMidiDriver::Open", "MIDIPortDispose", status);
  408. }
  409. destroy_virtual_output_ports:
  410. if (virtual_output_ports) {
  411. for (int i = 0; i < vo_count; i++) {
  412. delete virtual_output_ports[i];
  413. }
  414. delete[] virtual_output_ports;
  415. virtual_output_ports = 0;
  416. }
  417. destroy_virtual_input_ports:
  418. if (virtual_input_ports) {
  419. for (int i = 0; i < vi_count; i++) {
  420. delete virtual_input_ports[i];
  421. }
  422. delete[] virtual_input_ports;
  423. virtual_input_ports = 0;
  424. }
  425. destroy_client:
  426. status = MIDIClientDispose(client);
  427. if (status != noErr) {
  428. WriteMacOSError("JackCoreMidiDriver::Open", "MIDIClientDispose",
  429. status);
  430. }
  431. client = 0;
  432. return -1;
  433. }
  434. int
  435. JackCoreMidiDriver::Read()
  436. {
  437. jack_nframes_t buffer_size = fEngineControl->fBufferSize;
  438. for (int i = 0; i < num_physical_inputs; i++) {
  439. physical_input_ports[i]->ProcessJack(GetInputBuffer(i), buffer_size);
  440. }
  441. for (int i = 0; i < num_virtual_inputs; i++) {
  442. virtual_input_ports[i]->
  443. ProcessJack(GetInputBuffer(num_physical_inputs + i), buffer_size);
  444. }
  445. return 0;
  446. }
  447. int
  448. JackCoreMidiDriver::Start()
  449. {
  450. jack_info("JackCoreMidiDriver::Start - Starting driver.");
  451. JackMidiDriver::Start();
  452. int pi_count = 0;
  453. int po_count = 0;
  454. int vi_count = 0;
  455. int vo_count = 0;
  456. jack_info("JackCoreMidiDriver::Start - Enabling physical input ports.");
  457. for (; pi_count < num_physical_inputs; pi_count++) {
  458. if (physical_input_ports[pi_count]->Start() < 0) {
  459. jack_error("JackCoreMidiDriver::Start - Failed to enable physical "
  460. "input port.");
  461. goto stop_physical_input_ports;
  462. }
  463. }
  464. jack_info("JackCoreMidiDriver::Start - Enabling physical output ports.");
  465. for (; po_count < num_physical_outputs; po_count++) {
  466. if (physical_output_ports[po_count]->Start() < 0) {
  467. jack_error("JackCoreMidiDriver::Start - Failed to enable physical "
  468. "output port.");
  469. goto stop_physical_output_ports;
  470. }
  471. }
  472. jack_info("JackCoreMidiDriver::Start - Enabling virtual input ports.");
  473. for (; vi_count < num_virtual_inputs; vi_count++) {
  474. if (virtual_input_ports[vi_count]->Start() < 0) {
  475. jack_error("JackCoreMidiDriver::Start - Failed to enable virtual "
  476. "input port.");
  477. goto stop_virtual_input_ports;
  478. }
  479. }
  480. jack_info("JackCoreMidiDriver::Start - Enabling virtual output ports.");
  481. for (; vo_count < num_virtual_outputs; vo_count++) {
  482. if (virtual_output_ports[vo_count]->Start() < 0) {
  483. jack_error("JackCoreMidiDriver::Start - Failed to enable virtual "
  484. "output port.");
  485. goto stop_virtual_output_ports;
  486. }
  487. }
  488. jack_info("JackCoreMidiDriver::Start - Driver started.");
  489. return 0;
  490. stop_virtual_output_ports:
  491. for (int i = 0; i < vo_count; i++) {
  492. if (virtual_output_ports[i]->Stop() < 0) {
  493. jack_error("JackCoreMidiDriver::Start - Failed to disable virtual "
  494. "output port.");
  495. }
  496. }
  497. stop_virtual_input_ports:
  498. for (int i = 0; i < vi_count; i++) {
  499. if (virtual_input_ports[i]->Stop() < 0) {
  500. jack_error("JackCoreMidiDriver::Start - Failed to disable virtual "
  501. "input port.");
  502. }
  503. }
  504. stop_physical_output_ports:
  505. for (int i = 0; i < po_count; i++) {
  506. if (physical_output_ports[i]->Stop() < 0) {
  507. jack_error("JackCoreMidiDriver::Start - Failed to disable "
  508. "physical output port.");
  509. }
  510. }
  511. stop_physical_input_ports:
  512. for (int i = 0; i < pi_count; i++) {
  513. if (physical_input_ports[i]->Stop() < 0) {
  514. jack_error("JackCoreMidiDriver::Start - Failed to disable "
  515. "physical input port.");
  516. }
  517. }
  518. return -1;
  519. }
  520. int
  521. JackCoreMidiDriver::Stop()
  522. {
  523. int result = 0;
  524. jack_info("JackCoreMidiDriver::Stop - disabling physical input ports.");
  525. for (int i = 0; i < num_physical_inputs; i++) {
  526. if (physical_input_ports[i]->Stop() < 0) {
  527. jack_error("JackCoreMidiDriver::Stop - Failed to disable physical "
  528. "input port.");
  529. result = -1;
  530. }
  531. }
  532. jack_info("JackCoreMidiDriver::Stop - disabling physical output ports.");
  533. for (int i = 0; i < num_physical_outputs; i++) {
  534. if (physical_output_ports[i]->Stop() < 0) {
  535. jack_error("JackCoreMidiDriver::Stop - Failed to disable physical "
  536. "output port.");
  537. result = -1;
  538. }
  539. }
  540. jack_info("JackCoreMidiDriver::Stop - disabling virtual input ports.");
  541. for (int i = 0; i < num_virtual_inputs; i++) {
  542. if (virtual_input_ports[i]->Stop() < 0) {
  543. jack_error("JackCoreMidiDriver::Stop - Failed to disable virtual "
  544. "input port.");
  545. result = -1;
  546. }
  547. }
  548. jack_info("JackCoreMidiDriver::Stop - disabling virtual output ports.");
  549. for (int i = 0; i < num_virtual_outputs; i++) {
  550. if (virtual_output_ports[i]->Stop() < 0) {
  551. jack_error("JackCoreMidiDriver::Stop - Failed to disable virtual "
  552. "output port.");
  553. result = -1;
  554. }
  555. }
  556. return result;
  557. }
  558. int
  559. JackCoreMidiDriver::Write()
  560. {
  561. jack_nframes_t buffer_size = fEngineControl->fBufferSize;
  562. for (int i = 0; i < num_physical_outputs; i++) {
  563. physical_output_ports[i]->ProcessJack(GetOutputBuffer(i), buffer_size);
  564. }
  565. for (int i = 0; i < num_virtual_outputs; i++) {
  566. virtual_output_ports[i]->
  567. ProcessJack(GetOutputBuffer(num_physical_outputs + i),
  568. buffer_size);
  569. }
  570. return 0;
  571. }
  572. #ifdef __cplusplus
  573. extern "C" {
  574. #endif
  575. SERVER_EXPORT jack_driver_desc_t * driver_get_descriptor()
  576. {
  577. jack_driver_desc_t * desc;
  578. unsigned int i;
  579. desc = (jack_driver_desc_t*)calloc (1, sizeof (jack_driver_desc_t));
  580. strcpy(desc->name, "coremidi"); // size MUST be less then JACK_DRIVER_NAME_MAX + 1
  581. strcpy(desc->desc, "Apple CoreMIDI API based MIDI backend"); // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
  582. desc->nparams = 2;
  583. desc->params = (jack_driver_param_desc_t*)calloc (desc->nparams, sizeof (jack_driver_param_desc_t));
  584. i = 0;
  585. strcpy(desc->params[i].name, "inchannels");
  586. desc->params[i].character = 'i';
  587. desc->params[i].type = JackDriverParamInt;
  588. desc->params[i].value.ui = 0;
  589. strcpy(desc->params[i].short_desc, "CoreMIDI virtual bus");
  590. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  591. i++;
  592. strcpy(desc->params[i].name, "outchannels");
  593. desc->params[i].character = 'o';
  594. desc->params[i].type = JackDriverParamInt;
  595. desc->params[i].value.ui = 0;
  596. strcpy(desc->params[i].short_desc, "CoreMIDI virtual bus");
  597. strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
  598. return desc;
  599. }
  600. SERVER_EXPORT Jack::JackDriverClientInterface* driver_initialize(Jack::JackLockedEngine* engine, Jack::JackSynchro* table, const JSList* params)
  601. {
  602. const JSList * node;
  603. const jack_driver_param_t * param;
  604. int virtual_in = 0;
  605. int virtual_out = 0;
  606. for (node = params; node; node = jack_slist_next (node)) {
  607. param = (const jack_driver_param_t *) node->data;
  608. switch (param->character) {
  609. case 'i':
  610. virtual_in = param->value.ui;
  611. break;
  612. case 'o':
  613. virtual_out = param->value.ui;
  614. break;
  615. }
  616. }
  617. Jack::JackDriverClientInterface* driver = new Jack::JackCoreMidiDriver("system_midi", "coremidi", engine, table);
  618. if (driver->Open(1, 1, virtual_in, virtual_out, false, "in", "out", 0, 0) == 0) {
  619. return driver;
  620. } else {
  621. delete driver;
  622. return NULL;
  623. }
  624. }
  625. #ifdef __cplusplus
  626. }
  627. #endif