yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_ |
| 6 | #define MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_ |
| 7 | |
avi | 793390d | 2015-12-22 22:22:36 -0800 | [diff] [blame] | 8 | #include <stddef.h> |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 13 | #include "base/macros.h" |
brettw | 49ff017 | 2015-05-05 12:43:04 -0700 | [diff] [blame] | 14 | #include "media/midi/usb_midi_export.h" |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 15 | #include "media/midi/usb_midi_jack.h" |
| 16 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 17 | namespace midi { |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 18 | |
| 19 | // UsbMidiOutputStream converts MIDI data to USB-MIDI data. |
| 20 | // See "USB Device Class Definition for MIDI Devices" Release 1.0, |
| 21 | // Section 4 "USB-MIDI Event Packets" for details. |
brettw | 49ff017 | 2015-05-05 12:43:04 -0700 | [diff] [blame] | 22 | class USB_MIDI_EXPORT UsbMidiOutputStream { |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 23 | public: |
| 24 | explicit UsbMidiOutputStream(const UsbMidiJack& jack); |
| 25 | |
Peter Boström | 5e5c4fa | 2021-10-15 21:43:24 +0000 | [diff] [blame] | 26 | UsbMidiOutputStream(const UsbMidiOutputStream&) = delete; |
| 27 | UsbMidiOutputStream& operator=(const UsbMidiOutputStream&) = delete; |
| 28 | |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 29 | // Converts |data| to USB-MIDI data and send it to the jack. |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 30 | void Send(const std::vector<uint8_t>& data); |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 31 | |
yhirano@chromium.org | 3cecb69 | 2014-01-29 09:27:41 +0000 | [diff] [blame] | 32 | const UsbMidiJack& jack() const { return jack_; } |
| 33 | |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 34 | private: |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 35 | size_t GetSize(const std::vector<uint8_t>& data) const; |
| 36 | uint8_t Get(const std::vector<uint8_t>& data, size_t index) const; |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 37 | |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 38 | bool PushSysExMessage(const std::vector<uint8_t>& data, |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 39 | size_t* current, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 40 | std::vector<uint8_t>* data_to_send); |
| 41 | bool PushSysCommonMessage(const std::vector<uint8_t>& data, |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 42 | size_t* current, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 43 | std::vector<uint8_t>* data_to_send); |
| 44 | void PushSysRTMessage(const std::vector<uint8_t>& data, |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 45 | size_t* current, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 46 | std::vector<uint8_t>* data_to_send); |
| 47 | bool PushChannelMessage(const std::vector<uint8_t>& data, |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 48 | size_t* current, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 49 | std::vector<uint8_t>* data_to_send); |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 50 | |
| 51 | static const size_t kPacketContentSize = 3; |
| 52 | |
| 53 | UsbMidiJack jack_; |
| 54 | size_t pending_size_; |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame] | 55 | uint8_t pending_data_[kPacketContentSize]; |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 56 | bool is_sending_sysex_; |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 59 | } // namespace midi |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 60 | |
| 61 | #endif // MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_ |