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