MicroDexed is a compatible 6-operator-FM-synth based on the Teensy(-3.6/-4.0) Microcontroller. https://www.parasitstudio.de
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.

1605 lines
36KB

  1. /*
  2. MicroMDAEPiano
  3. MicroMDAEPiano is a port of the MDA-EPiano sound engine
  4. (https://sourceforge.net/projects/mda-vst/) for the Teensy-3.5/3.6 with audio shield.
  5. (c)2019 H. Wirtz <wirtz@parasitstudio.de>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef MIDI_DEVICES_H
  19. #define MIDI_DEVICES_H
  20. #include "config.h"
  21. /* #if defined(MIDI_DEVICE_USB)
  22. #include <midi_UsbTransport.h>
  23. #endif */
  24. #ifdef MIDI_DEVICE_USB_HOST
  25. #include <USBHost_t36.h>
  26. #endif
  27. #ifdef MIDI_DEVICE_DIN
  28. MIDI_CREATE_INSTANCE(HardwareSerial, MIDI_DEVICE_DIN, midi_serial);
  29. #endif
  30. #ifdef MIDI_DEVICE_USB_HOST
  31. USBHost usb_host;
  32. MIDIDevice midi_usb(usb_host);
  33. #endif
  34. /* #ifdef MIDI_DEVICE_USB
  35. static const unsigned sUsbTransportBufferSize = 16;
  36. typedef midi::UsbTransport<sUsbTransportBufferSize> UsbTransport;
  37. UsbTransport sUsbTransport;
  38. MIDI_CREATE_INSTANCE(UsbTransport, sUsbTransport, midi_onboard_usb);
  39. #endif */
  40. void handleNoteOn(byte inChannel, byte inNumber, byte inVelocity);
  41. void handleNoteOff(byte inChannel, byte inNumber, byte inVelocity);
  42. void handleControlChange(byte inChannel, byte inData1, byte inData2);
  43. void handleAfterTouch(byte inChannel, byte inPressure);
  44. void handlePitchBend(byte inChannel, int inPitch);
  45. void handleProgramChange(byte inChannel, byte inProgram);
  46. void handleSystemExclusive(byte *data, uint len);
  47. //void handleSystemExclusiveChunk(const byte *data, uint len, bool last);
  48. void handleTimeCodeQuarterFrame(byte data);
  49. void handleAfterTouchPoly(byte inChannel, byte inNumber, byte inVelocity);
  50. void handleSongSelect(byte inSong);
  51. void handleTuneRequest(void);
  52. void handleClock(void);
  53. void handleStart(void);
  54. void handleContinue(void);
  55. void handleStop(void);
  56. void handleActiveSensing(void);
  57. void handleSystemReset(void);
  58. //void handleRealTimeSystem(void);
  59. /*****************************************
  60. MIDI_DEVICE_DIN
  61. *****************************************/
  62. #ifdef MIDI_DEVICE_DIN
  63. void handleNoteOn_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity)
  64. {
  65. handleNoteOn(inChannel, inNumber, inVelocity);
  66. #ifdef DEBUG
  67. Serial.print(F("[MIDI_DIN] NoteOn"));
  68. #endif
  69. #ifdef MIDI_MERGE_THRU
  70. #ifdef MIDI_DEVICE_USB_HOST
  71. midi_usb.sendNoteOn(inNumber, inVelocity, inChannel);
  72. #ifdef DEBUG
  73. Serial.print(F(" THRU->MIDI_USB_HOST"));
  74. #endif
  75. #endif
  76. #ifdef MIDI_DEVICE_USB
  77. usbMIDI.sendNoteOn(inNumber, inVelocity, inChannel);
  78. #ifdef DEBUG
  79. Serial.print(F(" THRU->MIDI_USB"));
  80. #endif
  81. #endif
  82. #ifdef DEBUG
  83. Serial.println();
  84. #endif
  85. #endif
  86. }
  87. void handleNoteOff_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity)
  88. {
  89. handleNoteOff(inChannel, inNumber, inVelocity);
  90. #ifdef DEBUG
  91. Serial.print(F("[MIDI_DIN] NoteOff"));
  92. #endif
  93. #ifdef MIDI_MERGE_THRU
  94. #ifdef MIDI_DEVICE_USB_HOST
  95. midi_usb.sendNoteOff(inNumber, inVelocity, inChannel);
  96. #ifdef DEBUG
  97. Serial.print(F(" THRU->MIDI_USB_HOST"));
  98. #endif
  99. #endif
  100. #ifdef MIDI_DEVICE_USB
  101. usbMIDI.sendNoteOff(inNumber, inVelocity, inChannel);
  102. #ifdef DEBUG
  103. Serial.print(F(" THRU->MIDI_USB"));
  104. #endif
  105. #endif
  106. #ifdef DEBUG
  107. Serial.println();
  108. #endif
  109. #endif
  110. }
  111. void handleControlChange_MIDI_DEVICE_DIN(byte inChannel, byte inData1, byte inData2)
  112. {
  113. handleControlChange(inChannel, inData1, inData2);
  114. #ifdef DEBUG
  115. Serial.print(F("[MIDI_DIN] CC"));
  116. #endif
  117. #ifdef MIDI_MERGE_THRU
  118. #ifdef MIDI_DEVICE_USB_HOST
  119. midi_usb.sendControlChange(inData1, inData2, inChannel);
  120. #ifdef DEBUG
  121. Serial.print(F(" THRU->MIDI_USB_HOST"));
  122. #endif
  123. #endif
  124. #ifdef MIDI_DEVICE_USB
  125. usbMIDI.sendControlChange(inData1, inData2, inChannel);
  126. #ifdef DEBUG
  127. Serial.print(F(" THRU->MIDI_USB"));
  128. #endif
  129. #endif
  130. #ifdef DEBUG
  131. Serial.println();
  132. #endif
  133. #endif
  134. }
  135. void handleAfterTouch_MIDI_DEVICE_DIN(byte inChannel, byte inPressure)
  136. {
  137. handleAfterTouch(inChannel, inPressure);
  138. #ifdef DEBUG
  139. Serial.print(F("[MIDI_DIN] AT"));
  140. #endif
  141. #ifdef MIDI_MERGE_THRU
  142. #ifdef MIDI_DEVICE_USB_HOST
  143. midi_usb.sendAfterTouch(inPressure, inChannel);
  144. #ifdef DEBUG
  145. Serial.print(F(" THRU->MIDI_USB_HOST"));
  146. #endif
  147. #endif
  148. #ifdef MIDI_DEVICE_USB
  149. usbMIDI.sendAfterTouch(inPressure, inChannel);
  150. #ifdef DEBUG
  151. Serial.print(F(" THRU->MIDI_USB"));
  152. #endif
  153. #endif
  154. #ifdef DEBUG
  155. Serial.println();
  156. #endif
  157. #endif
  158. }
  159. void handlePitchBend_MIDI_DEVICE_DIN(byte inChannel, int inPitch)
  160. {
  161. handlePitchBend(inChannel, inPitch);
  162. #ifdef DEBUG
  163. Serial.print(F("[MIDI_DIN] PB"));
  164. #endif
  165. #ifdef MIDI_MERGE_THRU
  166. #ifdef MIDI_DEVICE_USB_HOST
  167. midi_usb.sendPitchBend(inPitch, inChannel);
  168. #ifdef DEBUG
  169. Serial.print(F(" THRU->MIDI_USB_HOST"));
  170. #endif
  171. #endif
  172. #ifdef MIDI_DEVICE_USB
  173. usbMIDI.sendPitchBend(inPitch, inChannel);
  174. #ifdef DEBUG
  175. Serial.print(F(" THRU->MIDI_USB"));
  176. #endif
  177. #endif
  178. #ifdef DEBUG
  179. Serial.println();
  180. #endif
  181. #endif
  182. }
  183. void handleProgramChange_MIDI_DEVICE_DIN(byte inChannel, byte inProgram)
  184. {
  185. handleProgramChange(inChannel, inProgram);
  186. #ifdef DEBUG
  187. Serial.print(F("[MIDI_DIN] PC"));
  188. #endif
  189. #ifdef MIDI_MERGE_THRU
  190. #ifdef MIDI_DEVICE_USB_HOST
  191. midi_usb.sendProgramChange(inProgram, inChannel);
  192. #ifdef DEBUG
  193. Serial.print(F(" THRU->MIDI_USB_HOST"));
  194. #endif
  195. #endif
  196. #ifdef MIDI_DEVICE_USB
  197. usbMIDI.sendProgramChange(inProgram, inChannel);
  198. #ifdef DEBUG
  199. Serial.print(F(" THRU->MIDI_USB"));
  200. #endif
  201. #endif
  202. #ifdef DEBUG
  203. Serial.println();
  204. #endif
  205. #endif
  206. }
  207. void handleSystemExclusive_MIDI_DEVICE_DIN(byte *data, uint len)
  208. {
  209. handleSystemExclusive(data, len);
  210. #ifdef DEBUG
  211. Serial.print(F("[MIDI_DIN] SysEx"));
  212. #endif
  213. #ifdef MIDI_MERGE_THRU
  214. #ifdef MIDI_DEVICE_USB_HOST
  215. midi_usb.sendSysEx(len, data);
  216. #ifdef DEBUG
  217. Serial.print(F(" THRU->MIDI_USB_HOST"));
  218. #endif
  219. #endif
  220. #ifdef MIDI_DEVICE_USB
  221. usbMIDI.sendSysEx(len, data);
  222. #ifdef DEBUG
  223. Serial.print(F(" THRU->MIDI_USB"));
  224. #endif
  225. #endif
  226. #ifdef DEBUG
  227. Serial.println();
  228. #endif
  229. #endif
  230. }
  231. /* void handleSystemExclusiveChunk_MIDI_DEVICE_DIN(byte *data, uint len, bool last)
  232. {
  233. handleSystemExclusiveChunk(data, len, last);
  234. #ifdef DEBUG
  235. Serial.print(F("[MIDI_DIN] SysExChunk"));
  236. #endif
  237. #ifdef MIDI_MERGE_THRU
  238. #ifdef MIDI_DEVICE_USB_HOST
  239. midi_usb.sendSysEx(len, data, last);
  240. #ifdef DEBUG
  241. Serial.print(F(" THRU->MIDI_USB_HOST"));
  242. #endif
  243. #endif
  244. #ifdef MIDI_DEVICE_USB
  245. usbMIDI.sendSysEx(len, data, last);
  246. #ifdef DEBUG
  247. Serial.print(F(" THRU->MIDI_USB"));
  248. #endif
  249. #endif
  250. #ifdef DEBUG
  251. Serial.println();
  252. #endif
  253. #endif
  254. } */
  255. void handleTimeCodeQuarterFrame_MIDI_DEVICE_DIN(byte data)
  256. {
  257. handleTimeCodeQuarterFrame(data);
  258. #ifdef DEBUG
  259. Serial.print(F("[MIDI_DIN] TimeCodeQuarterFrame"));
  260. #endif
  261. #ifdef MIDI_MERGE_THRU
  262. #ifdef MIDI_DEVICE_USB_HOST
  263. midi_usb.sendTimeCodeQuarterFrame(0xF1, data);
  264. #ifdef DEBUG
  265. Serial.print(F(" THRU->MIDI_USB_HOST"));
  266. #endif
  267. #endif
  268. #ifdef MIDI_DEVICE_USB
  269. usbMIDI.sendTimeCodeQuarterFrame(0xF1,data);
  270. #ifdef DEBUG
  271. Serial.print(F(" THRU->MIDI_USB"));
  272. #endif
  273. #endif
  274. #ifdef DEBUG
  275. Serial.println();
  276. #endif
  277. #endif
  278. }
  279. void handleAfterTouchPoly_MIDI_DEVICE_DIN(byte inChannel, byte inNumber, byte inVelocity)
  280. {
  281. handleAfterTouchPoly(inChannel, inNumber, inVelocity);
  282. #ifdef DEBUG
  283. Serial.print(F("[MIDI_DIN] AT-Poly"));
  284. #endif
  285. #ifdef MIDI_MERGE_THRU
  286. #ifdef MIDI_DEVICE_USB_HOST
  287. midi_usb.sendAfterTouch(inNumber, inVelocity, inChannel);
  288. #ifdef DEBUG
  289. Serial.print(F(" THRU->MIDI_USB_HOST"));
  290. #endif
  291. #endif
  292. #ifdef MIDI_DEVICE_USB
  293. usbMIDI.sendAfterTouch(inNumber, inVelocity, inChannel);
  294. #ifdef DEBUG
  295. Serial.print(F(" THRU->MIDI_USB"));
  296. #endif
  297. #endif
  298. #ifdef DEBUG
  299. Serial.println();
  300. #endif
  301. #endif
  302. }
  303. void handleSongSelect_MIDI_DEVICE_DIN(byte inSong)
  304. {
  305. handleSongSelect(inSong);
  306. #ifdef DEBUG
  307. Serial.print(F("[MIDI_DIN] SongSelect"));
  308. #endif
  309. #ifdef MIDI_MERGE_THRU
  310. #ifdef MIDI_DEVICE_USB_HOST
  311. midi_usb.sendSongSelect(inSong);
  312. #ifdef DEBUG
  313. Serial.print(F(" THRU->MIDI_USB_HOST"));
  314. #endif
  315. #endif
  316. #ifdef MIDI_DEVICE_USB
  317. usbMIDI.sendSongSelect(inSong);
  318. #ifdef DEBUG
  319. Serial.print(F(" THRU->MIDI_USB"));
  320. #endif
  321. #endif
  322. #ifdef DEBUG
  323. Serial.println();
  324. #endif
  325. #endif
  326. }
  327. void handleTuneRequest_MIDI_DEVICE_DIN(void)
  328. {
  329. handleTuneRequest();
  330. #ifdef DEBUG
  331. Serial.print(F("[MIDI_DIN] TuneRequest"));
  332. #endif
  333. #ifdef MIDI_MERGE_THRU
  334. #ifdef MIDI_DEVICE_USB_HOST
  335. midi_usb.sendTuneRequest();
  336. #ifdef DEBUG
  337. Serial.print(F(" THRU->MIDI_USB_HOST"));
  338. #endif
  339. #endif
  340. #ifdef MIDI_DEVICE_USB
  341. usbMIDI.sendTuneRequest();
  342. #ifdef DEBUG
  343. Serial.print(F(" THRU->MIDI_USB"));
  344. #endif
  345. #endif
  346. #ifdef DEBUG
  347. Serial.println();
  348. #endif
  349. #endif
  350. }
  351. void handleClock_MIDI_DEVICE_DIN(void)
  352. {
  353. handleClock();
  354. #ifdef DEBUG
  355. Serial.print(F("[MIDI_DIN] Clock"));
  356. #endif
  357. #ifdef MIDI_MERGE_THRU
  358. #ifdef MIDI_DEVICE_USB_HOST
  359. midi_usb.sendRealTime(midi::Clock);
  360. #ifdef DEBUG
  361. Serial.print(F(" THRU->MIDI_USB_HOST"));
  362. #endif
  363. #endif
  364. #ifdef MIDI_DEVICE_USB
  365. usbMIDI.sendRealTime(midi::Clock);
  366. #ifdef DEBUG
  367. Serial.print(F(" THRU->MIDI_USB"));
  368. #endif
  369. #endif
  370. #ifdef DEBUG
  371. Serial.println();
  372. #endif
  373. #endif
  374. }
  375. void handleStart_MIDI_DEVICE_DIN(void)
  376. {
  377. handleStart();
  378. #ifdef DEBUG
  379. Serial.print(F("[MIDI_DIN] Start"));
  380. #endif
  381. #ifdef MIDI_MERGE_THRU
  382. #ifdef MIDI_DEVICE_USB_HOST
  383. midi_usb.sendRealTime(midi::Start);
  384. #ifdef DEBUG
  385. Serial.print(F(" THRU->MIDI_USB_HOST"));
  386. #endif
  387. #endif
  388. #ifdef MIDI_DEVICE_USB
  389. usbMIDI.sendRealTime(midi::Start);
  390. #ifdef DEBUG
  391. Serial.print(F(" THRU->MIDI_USB"));
  392. #endif
  393. #endif
  394. #ifdef DEBUG
  395. Serial.println();
  396. #endif
  397. #endif
  398. }
  399. void handleContinue_MIDI_DEVICE_DIN(void)
  400. {
  401. handleContinue();
  402. #ifdef DEBUG
  403. Serial.print(F("[MIDI_DIN] Continue"));
  404. #endif
  405. #ifdef MIDI_MERGE_THRU
  406. #ifdef MIDI_DEVICE_USB_HOST
  407. midi_usb.sendRealTime(midi::Continue);
  408. #ifdef DEBUG
  409. Serial.print(F(" THRU->MIDI_USB_HOST"));
  410. #endif
  411. #endif
  412. #ifdef MIDI_DEVICE_USB
  413. usbMIDI.sendRealTime(midi::Continue);
  414. #ifdef DEBUG
  415. Serial.print(F(" THRU->MIDI_USB"));
  416. #endif
  417. #endif
  418. #ifdef DEBUG
  419. Serial.println();
  420. #endif
  421. #endif
  422. }
  423. void handleStop_MIDI_DEVICE_DIN(void)
  424. {
  425. handleStop();
  426. #ifdef DEBUG
  427. Serial.print(F("[MIDI_DIN] Stop"));
  428. #endif
  429. #ifdef MIDI_MERGE_THRU
  430. #ifdef MIDI_DEVICE_USB_HOST
  431. midi_usb.sendRealTime(midi::Stop);
  432. #ifdef DEBUG
  433. Serial.print(F(" THRU->MIDI_USB_HOST"));
  434. #endif
  435. #endif
  436. #ifdef MIDI_DEVICE_USB
  437. usbMIDI.sendRealTime(midi::Stop);
  438. #ifdef DEBUG
  439. Serial.print(F(" THRU->MIDI_USB"));
  440. #endif
  441. #endif
  442. #ifdef DEBUG
  443. Serial.println();
  444. #endif
  445. #endif
  446. }
  447. void handleActiveSensing_MIDI_DEVICE_DIN(void)
  448. {
  449. handleActiveSensing();
  450. #ifdef DEBUG
  451. Serial.print(F("[MIDI_DIN] ActiveSensing"));
  452. #endif
  453. #ifdef MIDI_MERGE_THRU
  454. #ifdef MIDI_DEVICE_USB_HOST
  455. midi_usb.sendRealTime(midi::ActiveSensing);
  456. #ifdef DEBUG
  457. Serial.print(F(" THRU->MIDI_USB_HOST"));
  458. #endif
  459. #endif
  460. #ifdef MIDI_DEVICE_USB
  461. usbMIDI.sendRealTime(midi::ActiveSensing);
  462. #ifdef DEBUG
  463. Serial.print(F(" THRU->MIDI_USB"));
  464. #endif
  465. #endif
  466. #ifdef DEBUG
  467. Serial.println();
  468. #endif
  469. #endif
  470. }
  471. void handleSystemReset_MIDI_DEVICE_DIN(void)
  472. {
  473. handleSystemReset();
  474. #ifdef DEBUG
  475. Serial.print(F("[MIDI_DIN] SystemReset"));
  476. #endif
  477. #ifdef MIDI_MERGE_THRU
  478. #ifdef MIDI_DEVICE_USB_HOST
  479. midi_usb.sendRealTime(midi::SystemReset);
  480. #ifdef DEBUG
  481. Serial.print(F(" THRU->MIDI_USB_HOST"));
  482. #endif
  483. #endif
  484. #ifdef MIDI_DEVICE_USB
  485. usbMIDI.sendRealTime(midi::SystemReset);
  486. #ifdef DEBUG
  487. Serial.print(F(" THRU->MIDI_USB"));
  488. #endif
  489. #endif
  490. #ifdef DEBUG
  491. Serial.println();
  492. #endif
  493. #endif
  494. }
  495. /* void handlRealTimeSysteme_MIDI_DEVICE_DIN(byte inRealTime)
  496. {
  497. handleRealTimeSystem();
  498. #ifdef DEBUG
  499. Serial.print(F("[MIDI_DIN] RealTimeSystem"));
  500. #endif
  501. #ifdef MIDI_MERGE_THRU
  502. #ifdef MIDI_DEVICE_USB_HOST
  503. midi_usb.sendRealTime(inRealTime);
  504. #ifdef DEBUG
  505. Serial.print(F(" THRU->MIDI_USB_HOST"));
  506. #endif
  507. #endif
  508. #ifdef MIDI_DEVICE_USB
  509. //usbMIDI.sendRealTime(inRealTIme);
  510. #ifdef DEBUG
  511. Serial.print(F(" THRU->MIDI_USB[NOTSUPPORTED]"));
  512. #endif
  513. #endif
  514. #ifdef DEBUG
  515. Serial.println();
  516. #endif
  517. #endif
  518. } */
  519. #endif // MIDI_DEVICE_DIN
  520. /*****************************************
  521. MIDI_DEVICE_USB_HOST
  522. *****************************************/
  523. #ifdef MIDI_DEVICE_USB_HOST
  524. void handleNoteOn_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity)
  525. {
  526. handleNoteOn(inChannel, inNumber, inVelocity);
  527. #ifdef DEBUG
  528. Serial.print(F("[MIDI_USB_HOST] NoteOn"));
  529. #endif
  530. #ifdef MIDI_MERGE_THRU
  531. #ifdef MIDI_DEVICE_DIN
  532. midi_serial.sendNoteOn(inNumber, inVelocity, inChannel);
  533. #ifdef DEBUG
  534. Serial.print(F(" THRU->MIDI_DIN"));
  535. #endif
  536. #endif
  537. #ifdef MIDI_DEVICE_USB
  538. usbMIDI.sendNoteOn(inNumber, inVelocity, inChannel);
  539. #ifdef DEBUG
  540. Serial.print(F(" THRU->MIDI_USB"));
  541. #endif
  542. #endif
  543. #ifdef DEBUG
  544. Serial.println();
  545. #endif
  546. #endif
  547. }
  548. void handleNoteOff_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity)
  549. {
  550. handleNoteOff(inChannel, inNumber, inVelocity);
  551. #ifdef DEBUG
  552. Serial.print(F("[MIDI_USB_HOST] NoteOff"));
  553. #endif
  554. #ifdef MIDI_MERGE_THRU
  555. #ifdef MIDI_DEVICE_DIN
  556. midi_serial.sendNoteOff(inNumber, inVelocity, inChannel);
  557. #ifdef DEBUG
  558. Serial.print(F(" THRU->MIDI_DIN"));
  559. #endif
  560. #endif
  561. #ifdef MIDI_DEVICE_USB
  562. usbMIDI.sendNoteOff(inNumber, inVelocity, inChannel);
  563. #ifdef DEBUG
  564. Serial.print(F(" THRU->MIDI_USB"));
  565. #endif
  566. #endif
  567. #ifdef DEBUG
  568. Serial.println();
  569. #endif
  570. #endif
  571. }
  572. void handleControlChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inData1, byte inData2)
  573. {
  574. handleControlChange(inChannel, inData1, inData2);
  575. #ifdef DEBUG
  576. Serial.print(F("[MIDI_USB_HOST] CC"));
  577. #endif
  578. #ifdef MIDI_MERGE_THRU
  579. #ifdef MIDI_DEVICE_DIN
  580. midi_serial.sendControlChange(inData1, inData2, inChannel);
  581. #ifdef DEBUG
  582. Serial.print(F(" THRU->MIDI_DIN"));
  583. #endif
  584. #endif
  585. #ifdef MIDI_DEVICE_USB
  586. usbMIDI.sendControlChange(inData1, inData2, inChannel);
  587. #ifdef DEBUG
  588. Serial.print(F(" THRU->MIDI_USB"));
  589. #endif
  590. #endif
  591. #ifdef DEBUG
  592. Serial.println();
  593. #endif
  594. #endif
  595. }
  596. void handleAfterTouch_MIDI_DEVICE_USB_HOST(byte inChannel, byte inPressure)
  597. {
  598. handleAfterTouch(inChannel, inPressure);
  599. #ifdef DEBUG
  600. Serial.print(F("[MIDI_USB_HOST] AT"));
  601. #endif
  602. #ifdef MIDI_MERGE_THRU
  603. #ifdef MIDI_DEVICE_DIN
  604. midi_serial.sendAfterTouch(inPressure, inChannel);
  605. #ifdef DEBUG
  606. Serial.print(F(" THRU->MIDI_DIN"));
  607. #endif
  608. #endif
  609. #ifdef MIDI_DEVICE_USB
  610. usbMIDI.sendAfterTouch(inPressure, inChannel);
  611. #ifdef DEBUG
  612. Serial.print(F(" THRU->MIDI_USB"));
  613. #endif
  614. #endif
  615. #ifdef DEBUG
  616. Serial.println();
  617. #endif
  618. #endif
  619. }
  620. void handlePitchBend_MIDI_DEVICE_USB_HOST(byte inChannel, int inPitch)
  621. {
  622. handlePitchBend(inChannel, inPitch);
  623. #ifdef DEBUG
  624. Serial.print(F("[MIDI_USB_HOST] PB"));
  625. #endif
  626. #ifdef MIDI_MERGE_THRU
  627. #ifdef MIDI_DEVICE_DIN
  628. midi_serial.sendPitchBend(inPitch, inChannel);
  629. #ifdef DEBUG
  630. Serial.print(F(" THRU->MIDI_DIN"));
  631. #endif
  632. #endif
  633. #ifdef MIDI_DEVICE_USB
  634. usbMIDI.sendPitchBend(inPitch, inChannel);
  635. #ifdef DEBUG
  636. Serial.print(F(" THRU->MIDI_USB"));
  637. #endif
  638. #endif
  639. #ifdef DEBUG
  640. Serial.println();
  641. #endif
  642. #endif
  643. }
  644. void handleProgramChange_MIDI_DEVICE_USB_HOST(byte inChannel, byte inProgram)
  645. {
  646. handleProgramChange(inChannel, inProgram);
  647. #ifdef DEBUG
  648. Serial.print(F("[MIDI_USB_HOST] PC"));
  649. #endif
  650. #ifdef MIDI_MERGE_THRU
  651. #ifdef MIDI_DEVICE_DIN
  652. midi_serial.sendProgramChange(inProgram, inChannel);
  653. #ifdef DEBUG
  654. Serial.print(F(" THRU->MIDI_DIN"));
  655. #endif
  656. #endif
  657. #ifdef MIDI_DEVICE_USB
  658. usbMIDI.sendProgramChange(inProgram, inChannel);
  659. #ifdef DEBUG
  660. Serial.print(F(" THRU->MIDI_USB"));
  661. #endif
  662. #endif
  663. #ifdef DEBUG
  664. Serial.println();
  665. #endif
  666. #endif
  667. }
  668. void handleSystemExclusive_MIDI_DEVICE_USB_HOST(byte *data, uint len)
  669. {
  670. handleSystemExclusive(data, len);
  671. #ifdef DEBUG
  672. Serial.print(F("[MIDI_USB_HOST] SysEx"));
  673. #endif
  674. #ifdef MIDI_MERGE_THRU
  675. #ifdef MIDI_DEVICE_DIN
  676. midi_serial.sendSysEx(len, data);
  677. #ifdef DEBUG
  678. Serial.print(F(" THRU->MIDI_DIN"));
  679. #endif
  680. #endif
  681. #ifdef MIDI_DEVICE_USB
  682. usbMIDI.sendSysEx(len, data);
  683. #ifdef DEBUG
  684. Serial.print(F(" THRU->MIDI_USB"));
  685. #endif
  686. #endif
  687. #ifdef DEBUG
  688. Serial.println();
  689. #endif
  690. #endif
  691. }
  692. /* void handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST(byte *data, uint len, bool last)
  693. {
  694. handleSystemExclusiveChunk(data, len, last);
  695. #ifdef DEBUG
  696. Serial.print(F("[MIDI_USB_HOST] SysExChunk"));
  697. #endif
  698. #ifdef MIDI_MERGE_THRU
  699. #ifdef MIDI_DEVICE_DIN
  700. midi_serial.sendSysEx(len, data, last);
  701. #ifdef DEBUG
  702. Serial.print(F(" THRU->MIDI_DIN"));
  703. #endif
  704. #endif
  705. #ifdef MIDI_DEVICE_USB
  706. usbMIDI.sendSysEx(len, data, last);
  707. #ifdef DEBUG
  708. Serial.print(F(" THRU->MIDI_USB"));
  709. #endif
  710. #endif
  711. #ifdef DEBUG
  712. Serial.println();
  713. #endif
  714. #endif
  715. } */
  716. void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB_HOST(midi::DataByte data)
  717. {
  718. handleTimeCodeQuarterFrame(data);
  719. #ifdef DEBUG
  720. Serial.print(F("[MIDI_USB_HOST] TimeCodeQuarterFrame"));
  721. #endif
  722. #ifdef MIDI_MERGE_THRU
  723. #ifdef MIDI_DEVICE_DIN
  724. midi_serial.sendTimeCodeQuarterFrame(data);
  725. #ifdef DEBUG
  726. Serial.print(F(" THRU->MIDI_DIN"));
  727. #endif
  728. #endif
  729. #ifdef MIDI_DEVICE_USB
  730. usbMIDI.sendTimeCodeQuarterFrame(0xF1,data);
  731. #ifdef DEBUG
  732. Serial.print(F(" THRU->MIDI_USB"));
  733. #endif
  734. #endif
  735. #ifdef DEBUG
  736. Serial.println();
  737. #endif
  738. #endif
  739. }
  740. void handleAfterTouchPoly_MIDI_DEVICE_USB_HOST(byte inChannel, byte inNumber, byte inVelocity)
  741. {
  742. handleAfterTouchPoly(inChannel, inNumber, inVelocity);
  743. #ifdef DEBUG
  744. Serial.print(F("[MIDI_USB_HOST] AT-Poly"));
  745. #endif
  746. #ifdef MIDI_MERGE_THRU
  747. #ifdef MIDI_DEVICE_DIN
  748. midi_serial.sendAfterTouch(inNumber, inVelocity, inChannel);
  749. #ifdef DEBUG
  750. Serial.print(F(" THRU->DIN"));
  751. #endif
  752. #endif
  753. #ifdef MIDI_DEVICE_USB
  754. usbMIDI.sendAfterTouch(inNumber, inVelocity, inChannel);
  755. #ifdef DEBUG
  756. Serial.print(F(" THRU->MIDI_USB"));
  757. #endif
  758. #endif
  759. #ifdef DEBUG
  760. Serial.println();
  761. #endif
  762. #endif
  763. }
  764. void handleSongSelect_MIDI_DEVICE_USB_HOST(byte inSong)
  765. {
  766. handleSongSelect(inSong);
  767. #ifdef DEBUG
  768. Serial.print(F("[MIDI_USB_HOST] SongSelect"));
  769. #endif
  770. #ifdef MIDI_MERGE_THRU
  771. #ifdef MIDI_DEVICE_DIN
  772. midi_serial.sendSongSelect(inSong);
  773. #ifdef DEBUG
  774. Serial.print(F(" THRU->MIDI_DIN"));
  775. #endif
  776. #endif
  777. #ifdef MIDI_DEVICE_USB
  778. usbMIDI.sendSongSelect(inSong);
  779. #ifdef DEBUG
  780. Serial.print(F(" THRU->MIDI_USB"));
  781. #endif
  782. #endif
  783. #ifdef DEBUG
  784. Serial.println();
  785. #endif
  786. #endif
  787. }
  788. void handleTuneRequest_MIDI_DEVICE_USB_HOST(void)
  789. {
  790. handleTuneRequest();
  791. #ifdef DEBUG
  792. Serial.print(F("[MIDI_USB_HOST] TuneRequest"));
  793. #endif
  794. #ifdef MIDI_MERGE_THRU
  795. #ifdef MIDI_DEVICE_DIN
  796. midi_serial.sendTuneRequest();
  797. #ifdef DEBUG
  798. Serial.print(F(" THRU->MIDI_DIN"));
  799. #endif
  800. #endif
  801. #ifdef MIDI_DEVICE_USB
  802. usbMIDI.sendTuneRequest();
  803. #ifdef DEBUG
  804. Serial.print(F(" THRU->MIDI_USB"));
  805. #endif
  806. #endif
  807. #ifdef DEBUG
  808. Serial.println();
  809. #endif
  810. #endif
  811. }
  812. void handleClock_MIDI_DEVICE_USB_HOST(void)
  813. {
  814. handleClock();
  815. #ifdef DEBUG
  816. Serial.print(F("[MIDI_USB_HOST] Clock"));
  817. #endif
  818. #ifdef MIDI_MERGE_THRU
  819. #ifdef MIDI_DEVICE_DIN
  820. midi_serial.sendRealTime(midi::Clock);
  821. #ifdef DEBUG
  822. Serial.print(F(" THRU->MIDI_DIN"));
  823. #endif
  824. #endif
  825. #ifdef MIDI_DEVICE_USB
  826. usbMIDI.sendRealTime(midi::Clock);
  827. #ifdef DEBUG
  828. Serial.print(F(" THRU->MIDI_USB"));
  829. #endif
  830. #endif
  831. #ifdef DEBUG
  832. Serial.println();
  833. #endif
  834. #endif
  835. }
  836. void handleStart_MIDI_DEVICE_USB_HOST(void)
  837. {
  838. handleStart();
  839. #ifdef DEBUG
  840. Serial.print(F("[MIDI_USB_HOST] Start"));
  841. #endif
  842. #ifdef MIDI_MERGE_THRU
  843. #ifdef MIDI_DEVICE_DIN
  844. midi_serial.sendRealTime(midi::Start);
  845. #ifdef DEBUG
  846. Serial.print(F(" THRU->MIDI_DIN"));
  847. #endif
  848. #endif
  849. #ifdef MIDI_DEVICE_USB
  850. usbMIDI.sendRealTime(midi::Start);
  851. #ifdef DEBUG
  852. Serial.print(F(" THRU->MIDI_USB"));
  853. #endif
  854. #endif
  855. #ifdef DEBUG
  856. Serial.println();
  857. #endif
  858. #endif
  859. }
  860. void handleContinue_MIDI_DEVICE_USB_HOST(void)
  861. {
  862. handleContinue();
  863. #ifdef DEBUG
  864. Serial.print(F("[MIDI_USB_HOST] Continue"));
  865. #endif
  866. #ifdef MIDI_MERGE_THRU
  867. #ifdef MIDI_DEVICE_DIN
  868. midi_serial.sendRealTime(midi::Continue);
  869. #ifdef DEBUG
  870. Serial.print(F(" THRU->MIDI_DIN"));
  871. #endif
  872. #endif
  873. #ifdef MIDI_DEVICE_USB
  874. usbMIDI.sendRealTime(midi::Continue);
  875. #ifdef DEBUG
  876. Serial.print(F(" THRU->MIDI_USB"));
  877. #endif
  878. #endif
  879. #ifdef DEBUG
  880. Serial.println();
  881. #endif
  882. #endif
  883. }
  884. void handleStop_MIDI_DEVICE_USB_HOST(void)
  885. {
  886. handleStop();
  887. #ifdef DEBUG
  888. Serial.print(F("[MIDI_USB_HOST] Stop"));
  889. #endif
  890. #ifdef MIDI_MERGE_THRU
  891. #ifdef MIDI_DEVICE_DIN
  892. midi_serial.sendRealTime(midi::Stop);
  893. #ifdef DEBUG
  894. Serial.print(F(" THRU->MIDI_DIN"));
  895. #endif
  896. #endif
  897. #ifdef MIDI_DEVICE_USB
  898. usbMIDI.sendRealTime(midi::Stop);
  899. #ifdef DEBUG
  900. Serial.print(F(" THRU->MIDI_USB"));
  901. #endif
  902. #endif
  903. #ifdef DEBUG
  904. Serial.println();
  905. #endif
  906. #endif
  907. }
  908. void handleActiveSensing_MIDI_DEVICE_USB_HOST(void)
  909. {
  910. handleActiveSensing();
  911. #ifdef DEBUG
  912. Serial.print(F("[MIDI_USB_HOST] ActiveSensing"));
  913. #endif
  914. #ifdef MIDI_MERGE_THRU
  915. #ifdef MIDI_DEVICE_DIN
  916. midi_serial.sendRealTime(midi::ActiveSensing);
  917. #ifdef DEBUG
  918. Serial.print(F(" THRU->MIDI_DIN"));
  919. #endif
  920. #endif
  921. #ifdef MIDI_DEVICE_USB
  922. usbMIDI.sendRealTime(midi::ActiveSensing);
  923. #ifdef DEBUG
  924. Serial.print(F(" THRU->MIDI_USB"));
  925. #endif
  926. #endif
  927. #ifdef DEBUG
  928. Serial.println();
  929. #endif
  930. #endif
  931. }
  932. void handleSystemReset_MIDI_DEVICE_USB_HOST(void)
  933. {
  934. handleSystemReset();
  935. #ifdef DEBUG
  936. Serial.print(F("[MIDI_USB_HOST] SystemReset"));
  937. #endif
  938. #ifdef MIDI_MERGE_THRU
  939. #ifdef MIDI_DEVICE_DIN
  940. midi_serial.sendRealTime(midi::SystemReset);
  941. #ifdef DEBUG
  942. Serial.print(F(" THRU->MIDI_DIN"));
  943. #endif
  944. #endif
  945. #ifdef MIDI_DEVICE_USB
  946. usbMIDI.sendRealTime(midi::SystemReset);
  947. #ifdef DEBUG
  948. Serial.print(F(" THRU->MIDI_USB"));
  949. #endif
  950. #endif
  951. #ifdef DEBUG
  952. Serial.println();
  953. #endif
  954. #endif
  955. }
  956. /* void handlRealTimeSysteme_MIDI_DEVICE_USB_HOST(midi::MidiType inRealTime)
  957. {
  958. handleRealTimeSystem();
  959. #ifdef DEBUG
  960. Serial.print(F("[MIDI_USB_HOST] RealTimeSystem"));
  961. #endif
  962. #ifdef MIDI_MERGE_THRU
  963. #ifdef MIDI_DEVICE_DIN
  964. midi_serial.sendRealTime(inRealTime);
  965. #ifdef DEBUG
  966. Serial.print(F(" THRU->MIDI_DIN"));
  967. #endif
  968. #endif
  969. #ifdef MIDI_DEVICE_USB
  970. usbMIDI.sendRealTime(inRealTime);
  971. #ifdef DEBUG
  972. Serial.print(F(" THRU->MIDI_USB"));
  973. #endif
  974. #endif
  975. #ifdef DEBUG
  976. Serial.println();
  977. #endif
  978. #endif
  979. } */
  980. #endif // MIDI_DEVICE_USB_HOST
  981. /*****************************************
  982. MIDI_DEVICE_USB
  983. *****************************************/
  984. #ifdef MIDI_DEVICE_USB
  985. void handleNoteOn_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity)
  986. {
  987. handleNoteOn(inChannel, inNumber, inVelocity);
  988. #ifdef DEBUG
  989. Serial.print(F("[MIDI_USB] NoteOn"));
  990. #endif
  991. #ifdef MIDI_MERGE_THRU
  992. #ifdef MIDI_DEVICE_DIN
  993. midi_serial.sendNoteOn(inNumber, inVelocity, inChannel);
  994. #ifdef DEBUG
  995. Serial.print(F(" THRU->MIDI_DIN"));
  996. #endif
  997. #endif
  998. #ifdef MIDI_DEVICE_USB_HOST
  999. midi_usb.sendNoteOn(inNumber, inVelocity, inChannel);
  1000. #ifdef DEBUG
  1001. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1002. #endif
  1003. #endif
  1004. #ifdef DEBUG
  1005. Serial.println();
  1006. #endif
  1007. #endif
  1008. }
  1009. void handleNoteOff_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity)
  1010. {
  1011. handleNoteOff(inChannel, inNumber, inVelocity);
  1012. #ifdef DEBUG
  1013. Serial.print(F("[MIDI_USB] NoteOff"));
  1014. #endif
  1015. #ifdef MIDI_MERGE_THRU
  1016. #ifdef MIDI_DEVICE_DIN
  1017. midi_serial.sendNoteOff(inNumber, inVelocity, inChannel);
  1018. #ifdef DEBUG
  1019. Serial.print(F(" THRU->MIDI_DIN"));
  1020. #endif
  1021. #endif
  1022. #ifdef MIDI_DEVICE_USB_HOST
  1023. midi_usb.sendNoteOff(inNumber, inVelocity, inChannel);
  1024. #ifdef DEBUG
  1025. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1026. #endif
  1027. #endif
  1028. #ifdef DEBUG
  1029. Serial.println();
  1030. #endif
  1031. #endif
  1032. }
  1033. void handleControlChange_MIDI_DEVICE_USB(byte inChannel, byte inData1, byte inData2)
  1034. {
  1035. handleControlChange(inChannel, inData1, inData2);
  1036. #ifdef DEBUG
  1037. Serial.print(F("[MIDI_USB] CC"));
  1038. #endif
  1039. #ifdef MIDI_MERGE_THRU
  1040. #ifdef MIDI_DEVICE_DIN
  1041. midi_serial.sendControlChange(inData1, inData2, inChannel);
  1042. #ifdef DEBUG
  1043. Serial.print(F(" THRU->MIDI_DIN"));
  1044. #endif
  1045. #endif
  1046. #ifdef MIDI_DEVICE_USB_HOST
  1047. midi_usb.sendControlChange(inData1, inData2, inChannel);
  1048. #ifdef DEBUG
  1049. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1050. #endif
  1051. #endif
  1052. #ifdef DEBUG
  1053. Serial.println();
  1054. #endif
  1055. #endif
  1056. }
  1057. void handleAfterTouch_MIDI_DEVICE_USB(byte inChannel, byte inPressure)
  1058. {
  1059. handleAfterTouch(inChannel, inPressure);
  1060. #ifdef DEBUG
  1061. Serial.print(F("[MIDI_USB] AT"));
  1062. #endif
  1063. #ifdef MIDI_MERGE_THRU
  1064. #ifdef MIDI_DEVICE_DIN
  1065. midi_serial.sendAfterTouch(inPressure, inChannel);
  1066. #ifdef DEBUG
  1067. Serial.print(F(" THRU->MIDI_DIN"));
  1068. #endif
  1069. #endif
  1070. #ifdef MIDI_DEVICE_USB_HOST
  1071. midi_usb.sendAfterTouch(inPressure, inChannel);
  1072. #ifdef DEBUG
  1073. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1074. #endif
  1075. #endif
  1076. #ifdef DEBUG
  1077. Serial.println();
  1078. #endif
  1079. #endif
  1080. }
  1081. void handlePitchBend_MIDI_DEVICE_USB(byte inChannel, int inPitch)
  1082. {
  1083. handlePitchBend(inChannel, inPitch);
  1084. #ifdef DEBUG
  1085. Serial.print(F("[MIDI_USB] PB"));
  1086. #endif
  1087. #ifdef MIDI_MERGE_THRU
  1088. #ifdef MIDI_DEVICE_DIN
  1089. midi_serial.sendPitchBend(inPitch, inChannel);
  1090. #ifdef DEBUG
  1091. Serial.print(F(" THRU->MIDI_DIN"));
  1092. #endif
  1093. #endif
  1094. #ifdef MIDI_DEVICE_USB_HOST
  1095. midi_usb.sendPitchBend(inPitch, inChannel);
  1096. #ifdef DEBUG
  1097. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1098. #endif
  1099. #endif
  1100. #ifdef DEBUG
  1101. Serial.println();
  1102. #endif
  1103. #endif
  1104. }
  1105. void handleProgramChange_MIDI_DEVICE_USB(byte inChannel, byte inProgram)
  1106. {
  1107. handleProgramChange(inChannel, inProgram);
  1108. #ifdef DEBUG
  1109. Serial.print(F("[MIDI_USB] PC"));
  1110. #endif
  1111. #ifdef MIDI_MERGE_THRU
  1112. #ifdef MIDI_DEVICE_DIN
  1113. midi_serial.sendProgramChange(inProgram, inChannel);
  1114. #ifdef DEBUG
  1115. Serial.print(F(" THRU->MIDI_DIN"));
  1116. #endif
  1117. #endif
  1118. #ifdef MIDI_DEVICE_USB_HOST
  1119. midi_usb.sendProgramChange(inProgram, inChannel);
  1120. #ifdef DEBUG
  1121. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1122. #endif
  1123. #endif
  1124. #ifdef DEBUG
  1125. Serial.println();
  1126. #endif
  1127. #endif
  1128. }
  1129. void handleSystemExclusive_MIDI_DEVICE_USB(byte *data, uint len)
  1130. {
  1131. handleSystemExclusive(data, len);
  1132. #ifdef DEBUG
  1133. Serial.print(F("[MIDI_USB] SysEx"));
  1134. #endif
  1135. #ifdef MIDI_MERGE_THRU
  1136. #ifdef MIDI_DEVICE_DIN
  1137. midi_serial.sendSysEx(len, data);
  1138. #ifdef DEBUG
  1139. Serial.print(F(" THRU->MIDI_DIN"));
  1140. #endif
  1141. #endif
  1142. #ifdef MIDI_DEVICE_USB_HOST
  1143. midi_usb.sendSysEx(len, data);
  1144. #ifdef DEBUG
  1145. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1146. #endif
  1147. #endif
  1148. #ifdef DEBUG
  1149. Serial.println();
  1150. #endif
  1151. #endif
  1152. }
  1153. /* void handleSystemExclusiveChunk_MIDI_DEVICE_USB(byte *data, uint len, bool last)
  1154. {
  1155. handleSystemExclusiveChunk(data, len, last);
  1156. #ifdef DEBUG
  1157. Serial.print(F("[MIDI_USB] SysExChunk"));
  1158. #endif
  1159. #ifdef MIDI_MERGE_THRU
  1160. #ifdef MIDI_DEVICE_DIN
  1161. midi_serial.sendSysEx(len, data, last);
  1162. #ifdef DEBUG
  1163. Serial.print(F(" THRU->MIDI_DIN"));
  1164. #endif
  1165. #endif
  1166. #ifdef MIDI_DEVICE_USB_HOST
  1167. midi_usb.sendSysEx(len, data, last);
  1168. #ifdef DEBUG
  1169. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1170. #endif
  1171. #endif
  1172. #ifdef DEBUG
  1173. Serial.println();
  1174. #endif
  1175. #endif
  1176. } */
  1177. void handleTimeCodeQuarterFrame_MIDI_DEVICE_USB(midi::DataByte data)
  1178. {
  1179. handleTimeCodeQuarterFrame(data);
  1180. #ifdef DEBUG
  1181. Serial.print(F("[MIDI_USB] TimeCodeQuarterFrame"));
  1182. #endif
  1183. #ifdef MIDI_MERGE_THRU
  1184. #ifdef MIDI_DEVICE_DIN
  1185. midi_serial.sendTimeCodeQuarterFrame(data);
  1186. #ifdef DEBUG
  1187. Serial.print(F(" THRU->MIDI_DIN"));
  1188. #endif
  1189. #endif
  1190. #ifdef MIDI_DEVICE_USB_HOST
  1191. midi_usb.sendTimeCodeQuarterFrame(0xF1, data);
  1192. #ifdef DEBUG
  1193. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1194. #endif
  1195. #endif
  1196. #ifdef DEBUG
  1197. Serial.println();
  1198. #endif
  1199. #endif
  1200. }
  1201. void handleAfterTouchPoly_MIDI_DEVICE_USB(byte inChannel, byte inNumber, byte inVelocity)
  1202. {
  1203. handleAfterTouchPoly(inChannel, inNumber, inVelocity);
  1204. #ifdef DEBUG
  1205. Serial.print(F("[MIDI_USB] AT-Poly"));
  1206. #endif
  1207. #ifdef MIDI_MERGE_THRU
  1208. #ifdef MIDI_DEVICE_DIN
  1209. midi_serial.sendAfterTouch(inNumber, inVelocity, inChannel);
  1210. #ifdef DEBUG
  1211. Serial.print(F(" THRU->DIN"));
  1212. #endif
  1213. #endif
  1214. #ifdef MIDI_DEVICE_USB_HOST
  1215. midi_usb.sendAfterTouch(inNumber, inVelocity, inChannel);
  1216. #ifdef DEBUG
  1217. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1218. #endif
  1219. #endif
  1220. #ifdef DEBUG
  1221. Serial.println();
  1222. #endif
  1223. #endif
  1224. }
  1225. void handleSongSelect_MIDI_DEVICE_USB(byte inSong)
  1226. {
  1227. handleSongSelect(inSong);
  1228. #ifdef DEBUG
  1229. Serial.print(F("[MIDI_USB] SongSelect"));
  1230. #endif
  1231. #ifdef MIDI_MERGE_THRU
  1232. #ifdef MIDI_DEVICE_DIN
  1233. midi_serial.sendSongSelect(inSong);
  1234. #ifdef DEBUG
  1235. Serial.print(F(" THRU->MIDI_DIN"));
  1236. #endif
  1237. #endif
  1238. #ifdef MIDI_DEVICE_USB_HOST
  1239. midi_usb.sendSongSelect(inSong);
  1240. #ifdef DEBUG
  1241. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1242. #endif
  1243. #endif
  1244. #ifdef DEBUG
  1245. Serial.println();
  1246. #endif
  1247. #endif
  1248. }
  1249. void handleTuneRequest_MIDI_DEVICE_USB(void)
  1250. {
  1251. handleTuneRequest();
  1252. #ifdef DEBUG
  1253. Serial.print(F("[MIDI_USB] TuneRequest"));
  1254. #endif
  1255. #ifdef MIDI_MERGE_THRU
  1256. #ifdef MIDI_DEVICE_DIN
  1257. midi_serial.sendTuneRequest();
  1258. #ifdef DEBUG
  1259. Serial.print(F(" THRU->MIDI_DIN"));
  1260. #endif
  1261. #endif
  1262. #ifdef MIDI_DEVICE_USB_HOST
  1263. midi_usb.sendTuneRequest();
  1264. #ifdef DEBUG
  1265. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1266. #endif
  1267. #endif
  1268. #ifdef DEBUG
  1269. Serial.println();
  1270. #endif
  1271. #endif
  1272. }
  1273. void handleClock_MIDI_DEVICE_USB(void)
  1274. {
  1275. handleClock();
  1276. #ifdef DEBUG
  1277. Serial.print(F("[MIDI_USB] Clock"));
  1278. #endif
  1279. #ifdef MIDI_MERGE_THRU
  1280. #ifdef MIDI_DEVICE_DIN
  1281. midi_serial.sendRealTime(midi::Clock);
  1282. #ifdef DEBUG
  1283. Serial.print(F(" THRU->MIDI_DIN"));
  1284. #endif
  1285. #endif
  1286. #ifdef MIDI_DEVICE_USB_HOST
  1287. midi_usb.sendRealTime(midi::Clock);
  1288. #ifdef DEBUG
  1289. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1290. #endif
  1291. #endif
  1292. #ifdef DEBUG
  1293. Serial.println();
  1294. #endif
  1295. #endif
  1296. }
  1297. void handleStart_MIDI_DEVICE_USB(void)
  1298. {
  1299. handleStart();
  1300. #ifdef DEBUG
  1301. Serial.print(F("[MIDI_USB] Start"));
  1302. #endif
  1303. #ifdef MIDI_MERGE_THRU
  1304. #ifdef MIDI_DEVICE_DIN
  1305. midi_serial.sendRealTime(midi::Start);
  1306. #ifdef DEBUG
  1307. Serial.print(F(" THRU->MIDI_DIN"));
  1308. #endif
  1309. #endif
  1310. #ifdef MIDI_DEVICE_USB_HOST
  1311. midi_usb.sendRealTime(midi::Start);
  1312. #ifdef DEBUG
  1313. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1314. #endif
  1315. #endif
  1316. #ifdef DEBUG
  1317. Serial.println();
  1318. #endif
  1319. #endif
  1320. }
  1321. void handleContinue_MIDI_DEVICE_USB(void)
  1322. {
  1323. handleContinue();
  1324. #ifdef DEBUG
  1325. Serial.print(F("[MIDI_USB] Continue"));
  1326. #endif
  1327. #ifdef MIDI_MERGE_THRU
  1328. #ifdef MIDI_DEVICE_DIN
  1329. midi_serial.sendRealTime(midi::Continue);
  1330. #ifdef DEBUG
  1331. Serial.print(F(" THRU->MIDI_DIN"));
  1332. #endif
  1333. #endif
  1334. #ifdef MIDI_DEVICE_USB_HOST
  1335. midi_usb.sendRealTime(midi::Continue);
  1336. #ifdef DEBUG
  1337. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1338. #endif
  1339. #endif
  1340. #ifdef DEBUG
  1341. Serial.println();
  1342. #endif
  1343. #endif
  1344. }
  1345. void handleStop_MIDI_DEVICE_USB(void)
  1346. {
  1347. handleStop();
  1348. #ifdef DEBUG
  1349. Serial.print(F("[MIDI_USB] Stop"));
  1350. #endif
  1351. #ifdef MIDI_MERGE_THRU
  1352. #ifdef MIDI_DEVICE_DIN
  1353. midi_serial.sendRealTime(midi::Stop);
  1354. #ifdef DEBUG
  1355. Serial.print(F(" THRU->MIDI_DIN"));
  1356. #endif
  1357. #endif
  1358. #ifdef MIDI_DEVICE_USB_HOST
  1359. midi_usb.sendRealTime(midi::Stop);
  1360. #ifdef DEBUG
  1361. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1362. #endif
  1363. #endif
  1364. #ifdef DEBUG
  1365. Serial.println();
  1366. #endif
  1367. #endif
  1368. }
  1369. void handleActiveSensing_MIDI_DEVICE_USB(void)
  1370. {
  1371. handleActiveSensing();
  1372. #ifdef DEBUG
  1373. Serial.print(F("[MIDI_USB] ActiveSensing"));
  1374. #endif
  1375. #ifdef MIDI_MERGE_THRU
  1376. #ifdef MIDI_DEVICE_DIN
  1377. midi_serial.sendRealTime(midi::ActiveSensing);
  1378. #ifdef DEBUG
  1379. Serial.print(F(" THRU->MIDI_DIN"));
  1380. #endif
  1381. #endif
  1382. #ifdef MIDI_DEVICE_USB_HOST
  1383. midi_usb.sendRealTime(midi::ActiveSensing);
  1384. #ifdef DEBUG
  1385. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1386. #endif
  1387. #endif
  1388. #ifdef DEBUG
  1389. Serial.println();
  1390. #endif
  1391. #endif
  1392. }
  1393. void handleSystemReset_MIDI_DEVICE_USB(void)
  1394. {
  1395. handleSystemReset();
  1396. #ifdef DEBUG
  1397. Serial.print(F("[MIDI_USB] SystemReset"));
  1398. #endif
  1399. #ifdef MIDI_MERGE_THRU
  1400. #ifdef MIDI_DEVICE_DIN
  1401. midi_serial.sendRealTime(midi::SystemReset);
  1402. #ifdef DEBUG
  1403. Serial.print(F(" THRU->MIDI_DIN"));
  1404. #endif
  1405. #endif
  1406. #ifdef MIDI_DEVICE_USB_HOST
  1407. midi_usb.sendRealTime(midi::SystemReset);
  1408. #ifdef DEBUG
  1409. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1410. #endif
  1411. #endif
  1412. #ifdef DEBUG
  1413. Serial.println();
  1414. #endif
  1415. #endif
  1416. }
  1417. /* void handleRealTimeSystem_MIDI_DEVICE_USB(byte inRealTime)
  1418. {
  1419. handleRealTimeSystem();
  1420. #ifdef DEBUG
  1421. Serial.print(F("[MIDI_USB] RealTimeSystem"));
  1422. #endif
  1423. #ifdef MIDI_MERGE_THRU
  1424. #ifdef MIDI_DEVICE_DIN
  1425. midi_serial.sendRealTime((midi::MidiType)inRealTime);
  1426. #ifdef DEBUG
  1427. Serial.print(F(" THRU->MIDI_DIN"));
  1428. #endif
  1429. #endif
  1430. #ifdef MIDI_DEVICE_USB_HOST
  1431. midi_usb.sendRealTime(inRealTime);
  1432. #ifdef DEBUG
  1433. Serial.print(F(" THRU->MIDI_USB_HOST"));
  1434. #endif
  1435. #endif
  1436. #ifdef DEBUG
  1437. Serial.println();
  1438. #endif
  1439. #endif
  1440. } */
  1441. #endif // MIDI_DEVICE_USB
  1442. /*****************************************
  1443. HELPER FUCNTIONS
  1444. *****************************************/
  1445. void setup_midi_devices(void)
  1446. {
  1447. #ifdef MIDI_DEVICE_DIN
  1448. // Start serial MIDI
  1449. midi_serial.begin(DEFAULT_MIDI_CHANNEL);
  1450. midi_serial.setHandleNoteOn(handleNoteOn_MIDI_DEVICE_DIN);
  1451. midi_serial.setHandleNoteOff(handleNoteOff_MIDI_DEVICE_DIN);
  1452. midi_serial.setHandleControlChange(handleControlChange_MIDI_DEVICE_DIN);
  1453. midi_serial.setHandleAfterTouchChannel(handleAfterTouch_MIDI_DEVICE_DIN);
  1454. midi_serial.setHandlePitchBend(handlePitchBend_MIDI_DEVICE_DIN);
  1455. midi_serial.setHandleProgramChange(handleProgramChange_MIDI_DEVICE_DIN);
  1456. midi_serial.setHandleSystemExclusive(handleSystemExclusive_MIDI_DEVICE_DIN);
  1457. //midi_serial.setHandleSystemExclusiveChunk(handleSystemExclusiveChunk_MIDI_DEVICE_DIN);
  1458. midi_serial.setHandleTimeCodeQuarterFrame(handleTimeCodeQuarterFrame_MIDI_DEVICE_DIN);
  1459. midi_serial.setHandleAfterTouchPoly(handleAfterTouchPoly_MIDI_DEVICE_DIN);
  1460. midi_serial.setHandleSongSelect(handleSongSelect_MIDI_DEVICE_DIN);
  1461. midi_serial.setHandleTuneRequest(handleTuneRequest_MIDI_DEVICE_DIN);
  1462. midi_serial.setHandleClock(handleClock_MIDI_DEVICE_DIN);
  1463. midi_serial.setHandleStart(handleStart_MIDI_DEVICE_DIN);
  1464. midi_serial.setHandleContinue(handleContinue_MIDI_DEVICE_DIN);
  1465. midi_serial.setHandleStop(handleStop_MIDI_DEVICE_DIN);
  1466. midi_serial.setHandleActiveSensing(handleActiveSensing_MIDI_DEVICE_DIN);
  1467. midi_serial.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_DIN);
  1468. //midi_serial.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_DIN);
  1469. Serial.println(F("MIDI_DEVICE_DIN enabled"));
  1470. #endif
  1471. // start up USB host
  1472. #ifdef MIDI_DEVICE_USB_HOST
  1473. usb_host.begin();
  1474. midi_usb.setHandleNoteOn(handleNoteOn_MIDI_DEVICE_USB_HOST);
  1475. midi_usb.setHandleNoteOff(handleNoteOff_MIDI_DEVICE_USB_HOST);
  1476. midi_usb.setHandleControlChange(handleControlChange_MIDI_DEVICE_USB_HOST);
  1477. midi_usb.setHandleAfterTouchChannel(handleAfterTouch_MIDI_DEVICE_USB_HOST);
  1478. midi_usb.setHandlePitchChange(handlePitchBend_MIDI_DEVICE_USB_HOST);
  1479. midi_usb.setHandleProgramChange(handleProgramChange_MIDI_DEVICE_USB_HOST);
  1480. midi_usb.setHandleSystemExclusive(handleSystemExclusive_MIDI_DEVICE_USB_HOST);
  1481. //midi_usb.setHandleSystemExclusiveChunk(handleSystemExclusiveChunk_MIDI_DEVICE_USB_HOST);
  1482. midi_usb.setHandleTimeCodeQuarterFrame(handleTimeCodeQuarterFrame_MIDI_DEVICE_USB_HOST);
  1483. midi_usb.setHandleAfterTouchPoly(handleAfterTouchPoly_MIDI_DEVICE_USB_HOST);
  1484. midi_usb.setHandleSongSelect(handleSongSelect_MIDI_DEVICE_USB_HOST);
  1485. midi_usb.setHandleTuneRequest(handleTuneRequest_MIDI_DEVICE_USB_HOST);
  1486. midi_usb.setHandleClock(handleClock_MIDI_DEVICE_USB_HOST);
  1487. midi_usb.setHandleStart(handleStart_MIDI_DEVICE_USB_HOST);
  1488. midi_usb.setHandleContinue(handleContinue_MIDI_DEVICE_USB_HOST);
  1489. midi_usb.setHandleStop(handleStop_MIDI_DEVICE_USB_HOST);
  1490. midi_usb.setHandleActiveSensing(handleActiveSensing_MIDI_DEVICE_USB_HOST);
  1491. midi_usb.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_USB_HOST);
  1492. //midi_usb.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_USB_HOST);
  1493. Serial.println(F("MIDI_DEVICE_USB_HOST enabled."));
  1494. #endif
  1495. // check for onboard USB-MIDI
  1496. #ifdef MIDI_DEVICE_USB
  1497. usbMIDI.begin();
  1498. usbMIDI.setHandleNoteOn(handleNoteOn_MIDI_DEVICE_USB);
  1499. usbMIDI.setHandleNoteOff(handleNoteOff_MIDI_DEVICE_USB);
  1500. usbMIDI.setHandleControlChange(handleControlChange_MIDI_DEVICE_USB);
  1501. usbMIDI.setHandleAfterTouchChannel(handleAfterTouch_MIDI_DEVICE_USB);
  1502. usbMIDI.setHandlePitchChange(handlePitchBend_MIDI_DEVICE_USB);
  1503. usbMIDI.setHandleProgramChange(handleProgramChange_MIDI_DEVICE_USB);
  1504. usbMIDI.setHandleSystemExclusive(handleSystemExclusive_MIDI_DEVICE_USB);
  1505. //usbMIDI.setHandleSystemExclusiveChunk(handleSystemExclusiveChunk_MIDI_DEVICE_USB);
  1506. usbMIDI.setHandleTimeCodeQuarterFrame(handleTimeCodeQuarterFrame_MIDI_DEVICE_USB);
  1507. usbMIDI.setHandleAfterTouchPoly(handleAfterTouchPoly_MIDI_DEVICE_USB);
  1508. usbMIDI.setHandleSongSelect(handleSongSelect_MIDI_DEVICE_USB);
  1509. usbMIDI.setHandleTuneRequest(handleTuneRequest_MIDI_DEVICE_USB);
  1510. usbMIDI.setHandleClock(handleClock_MIDI_DEVICE_USB);
  1511. usbMIDI.setHandleStart(handleStart_MIDI_DEVICE_USB);
  1512. usbMIDI.setHandleContinue(handleContinue_MIDI_DEVICE_USB);
  1513. usbMIDI.setHandleStop(handleStop_MIDI_DEVICE_USB);
  1514. usbMIDI.setHandleActiveSensing(handleActiveSensing_MIDI_DEVICE_USB);
  1515. usbMIDI.setHandleSystemReset(handleSystemReset_MIDI_DEVICE_USB);
  1516. //usbMIDI.setHandleRealTimeSystem(handleRealTimeSystem_MIDI_DEVICE_USB);
  1517. Serial.println(F("MIDI_DEVICE_USB enabled."));
  1518. #endif
  1519. }
  1520. void check_midi_devices(void)
  1521. {
  1522. #ifdef MIDI_DEVICE_DIN
  1523. midi_serial.read();
  1524. #endif
  1525. #ifdef MIDI_DEVICE_USB
  1526. usbMIDI.read();
  1527. #endif
  1528. #ifdef MIDI_DEVICE_USB_HOST
  1529. usb_host.Task();
  1530. midi_usb.read();
  1531. #endif
  1532. }
  1533. #endif // MIDI_DEVICES_H