| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_MIDI_MIDI_MESSAGE_QUEUE_H_ | 5 #ifndef MEDIA_MIDI_MIDI_MESSAGE_QUEUE_H_ |
| 6 #define MEDIA_MIDI_MIDI_MESSAGE_QUEUE_H_ | 6 #define MEDIA_MIDI_MIDI_MESSAGE_QUEUE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "media/base/media_export.h" | 12 #include "media/midi/midi_export.h" |
| 13 | 13 |
| 14 namespace media { | 14 namespace media { |
| 15 | 15 |
| 16 // A simple message splitter for possibly unsafe/corrupted MIDI data stream. | 16 // A simple message splitter for possibly unsafe/corrupted MIDI data stream. |
| 17 // This class allows you to: | 17 // This class allows you to: |
| 18 // - maintain fragmented MIDI message. | 18 // - maintain fragmented MIDI message. |
| 19 // - skip any invalid data sequence. | 19 // - skip any invalid data sequence. |
| 20 // - reorder MIDI messages so that "System Real Time Message", which can be | 20 // - reorder MIDI messages so that "System Real Time Message", which can be |
| 21 // inserted at any point of the byte stream, is placed at the boundary of | 21 // inserted at any point of the byte stream, is placed at the boundary of |
| 22 // complete MIDI messages. | 22 // complete MIDI messages. |
| 23 // - (Optional) reconstruct complete MIDI messages from data stream where | 23 // - (Optional) reconstruct complete MIDI messages from data stream where |
| 24 // MIDI status byte is abbreviated (a.k.a. "running status"). | 24 // MIDI status byte is abbreviated (a.k.a. "running status"). |
| 25 // | 25 // |
| 26 // Example (pseudo message loop): | 26 // Example (pseudo message loop): |
| 27 // MidiMessageQueue queue(true); // true to support "running status" | 27 // MidiMessageQueue queue(true); // true to support "running status" |
| 28 // while (true) { | 28 // while (true) { |
| 29 // if (is_incoming_midi_data_available()) { | 29 // if (is_incoming_midi_data_available()) { |
| 30 // std::vector<uint8> incoming_data; | 30 // std::vector<uint8> incoming_data; |
| 31 // read_incoming_midi_data(&incoming_data) | 31 // read_incoming_midi_data(&incoming_data) |
| 32 // queue.Add(incoming_data); | 32 // queue.Add(incoming_data); |
| 33 // } | 33 // } |
| 34 // while (true) { | 34 // while (true) { |
| 35 // std::vector<uint8> next_message; | 35 // std::vector<uint8> next_message; |
| 36 // queue.Get(&next_message); | 36 // queue.Get(&next_message); |
| 37 // if (!next_message.empty()) | 37 // if (!next_message.empty()) |
| 38 // dispatch(next_message); | 38 // dispatch(next_message); |
| 39 // } | 39 // } |
| 40 // } | 40 // } |
| 41 class MEDIA_EXPORT MidiMessageQueue { | 41 class MIDI_EXPORT MidiMessageQueue { |
| 42 public: | 42 public: |
| 43 // Initializes the queue. Set true to |allow_running_status| to enable | 43 // Initializes the queue. Set true to |allow_running_status| to enable |
| 44 // "MIDI running status" reconstruction. | 44 // "MIDI running status" reconstruction. |
| 45 explicit MidiMessageQueue(bool allow_running_status); | 45 explicit MidiMessageQueue(bool allow_running_status); |
| 46 ~MidiMessageQueue(); | 46 ~MidiMessageQueue(); |
| 47 | 47 |
| 48 // Enqueues |data| to the internal buffer. | 48 // Enqueues |data| to the internal buffer. |
| 49 void Add(const std::vector<uint8>& data); | 49 void Add(const std::vector<uint8>& data); |
| 50 void Add(const uint8* data, size_t length); | 50 void Add(const uint8* data, size_t length); |
| 51 | 51 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 private: | 63 private: |
| 64 std::deque<uint8> queue_; | 64 std::deque<uint8> queue_; |
| 65 std::vector<uint8> next_message_; | 65 std::vector<uint8> next_message_; |
| 66 const bool allow_running_status_; | 66 const bool allow_running_status_; |
| 67 DISALLOW_COPY_AND_ASSIGN(MidiMessageQueue); | 67 DISALLOW_COPY_AND_ASSIGN(MidiMessageQueue); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace media | 70 } // namespace media |
| 71 | 71 |
| 72 #endif // MEDIA_MIDI_MIDI_MESSAGE_QUEUE_H_ | 72 #endif // MEDIA_MIDI_MIDI_MESSAGE_QUEUE_H_ |
| OLD | NEW |