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 Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 8 | #include <stdint.h> |
| 9 | |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 12 | #include "base/macros.h" |
brettw | 49ff017 | 2015-05-05 12:43:04 -0700 | [diff] [blame] | 13 | #include "media/midi/usb_midi_export.h" |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 14 | #include "media/midi/usb_midi_jack.h" |
| 15 | |
| 16 | namespace media { |
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 | |
| 26 | // Converts |data| to USB-MIDI data and send it to the jack. |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 27 | void Send(const std::vector<uint8_t>& data); |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 28 | |
yhirano@chromium.org | 3cecb69 | 2014-01-29 09:27:41 +0000 | [diff] [blame] | 29 | const UsbMidiJack& jack() const { return jack_; } |
| 30 | |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 31 | private: |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 32 | size_t GetSize(const std::vector<uint8_t>& data) const; |
| 33 | 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] | 34 | |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 35 | bool PushSysExMessage(const std::vector<uint8_t>& data, |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 36 | size_t* current, |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 37 | std::vector<uint8_t>* data_to_send); |
| 38 | bool PushSysCommonMessage(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 | void PushSysRTMessage(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 | bool PushChannelMessage(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); |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 47 | |
| 48 | static const size_t kPacketContentSize = 3; |
| 49 | |
| 50 | UsbMidiJack jack_; |
| 51 | size_t pending_size_; |
Avi Drissman | 3528fd0 | 2015-12-18 20:11:31 -0500 | [diff] [blame^] | 52 | uint8_t pending_data_[kPacketContentSize]; |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 53 | bool is_sending_sysex_; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(UsbMidiOutputStream); |
| 56 | }; |
| 57 | |
toyoshim | e147c5e | 2015-05-07 21:58:31 -0700 | [diff] [blame] | 58 | } // namespace midi |
yhirano@chromium.org | 0e3c3ea | 2014-01-22 10:39:41 +0000 | [diff] [blame] | 59 | } // namespace media |
| 60 | |
| 61 | #endif // MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_ |