Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / media / midi / usb_midi_output_stream.h
blob1d98d584fd0c6e4a635968460fd869ef7b171fdf
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.
5 #ifndef MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_
6 #define MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "media/base/media_export.h"
12 #include "media/midi/usb_midi_jack.h"
14 namespace media {
16 // UsbMidiOutputStream converts MIDI data to USB-MIDI data.
17 // See "USB Device Class Definition for MIDI Devices" Release 1.0,
18 // Section 4 "USB-MIDI Event Packets" for details.
19 class MEDIA_EXPORT UsbMidiOutputStream {
20 public:
21 explicit UsbMidiOutputStream(const UsbMidiJack& jack);
23 // Converts |data| to USB-MIDI data and send it to the jack.
24 void Send(const std::vector<uint8>& data);
26 const UsbMidiJack& jack() const { return jack_; }
28 private:
29 size_t GetSize(const std::vector<uint8>& data) const;
30 uint8_t Get(const std::vector<uint8>& data, size_t index) const;
32 bool PushSysExMessage(const std::vector<uint8>& data,
33 size_t* current,
34 std::vector<uint8>* data_to_send);
35 bool PushSysCommonMessage(const std::vector<uint8>& data,
36 size_t* current,
37 std::vector<uint8>* data_to_send);
38 void PushSysRTMessage(const std::vector<uint8>& data,
39 size_t* current,
40 std::vector<uint8>* data_to_send);
41 bool PushChannelMessage(const std::vector<uint8>& data,
42 size_t* current,
43 std::vector<uint8>* data_to_send);
45 static const size_t kPacketContentSize = 3;
47 UsbMidiJack jack_;
48 size_t pending_size_;
49 uint8 pending_data_[kPacketContentSize];
50 bool is_sending_sysex_;
52 DISALLOW_COPY_AND_ASSIGN(UsbMidiOutputStream);
55 } // namespace media
57 #endif // MEDIA_MIDI_USB_MIDI_OUTPUT_STREAM_H_