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 #include "media/midi/midi_message_queue.h" | 5 #include "media/midi/midi_message_queue.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/midi/midi_message_util.h" | 10 #include "media/midi/midi_message_util.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 bool IsFirstStatusByte(uint8 data) { | 22 bool IsFirstStatusByte(uint8 data) { |
23 return !IsDataByte(data) && data != kEndOfSysEx; | 23 return !IsDataByte(data) && data != kEndOfSysEx; |
24 } | 24 } |
25 | 25 |
26 bool IsSystemRealTimeMessage(uint8 data) { | 26 bool IsSystemRealTimeMessage(uint8 data) { |
27 return 0xf8 <= data && data <= 0xff; | 27 return 0xf8 <= data && data <= 0xff; |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 MIDIMessageQueue::MIDIMessageQueue(bool allow_running_status) | 32 MidiMessageQueue::MidiMessageQueue(bool allow_running_status) |
33 : allow_running_status_(allow_running_status) {} | 33 : allow_running_status_(allow_running_status) {} |
34 | 34 |
35 MIDIMessageQueue::~MIDIMessageQueue() {} | 35 MidiMessageQueue::~MidiMessageQueue() {} |
36 | 36 |
37 void MIDIMessageQueue::Add(const std::vector<uint8>& data) { | 37 void MidiMessageQueue::Add(const std::vector<uint8>& data) { |
38 queue_.insert(queue_.end(), data.begin(), data.end()); | 38 queue_.insert(queue_.end(), data.begin(), data.end()); |
39 } | 39 } |
40 | 40 |
41 void MIDIMessageQueue::Add(const uint8* data, size_t length) { | 41 void MidiMessageQueue::Add(const uint8* data, size_t length) { |
42 queue_.insert(queue_.end(), data, data + length); | 42 queue_.insert(queue_.end(), data, data + length); |
43 } | 43 } |
44 | 44 |
45 void MIDIMessageQueue::Get(std::vector<uint8>* message) { | 45 void MidiMessageQueue::Get(std::vector<uint8>* message) { |
46 message->clear(); | 46 message->clear(); |
47 | 47 |
48 while (true) { | 48 while (true) { |
49 if (queue_.empty()) | 49 if (queue_.empty()) |
50 return; | 50 return; |
51 | 51 |
52 const uint8 next = queue_.front(); | 52 const uint8 next = queue_.front(); |
53 queue_.pop_front(); | 53 queue_.pop_front(); |
54 | 54 |
55 // "System Real Time Messages" is a special kind of MIDI messages, which can | 55 // "System Real Time Messages" is a special kind of MIDI messages, which can |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (next == kEndOfSysEx) { | 91 if (next == kEndOfSysEx) { |
92 std::swap(*message, next_message_); | 92 std::swap(*message, next_message_); |
93 next_message_.clear(); | 93 next_message_.clear(); |
94 return; | 94 return; |
95 } | 95 } |
96 continue; | 96 continue; |
97 } | 97 } |
98 | 98 |
99 DCHECK(IsDataByte(next)); | 99 DCHECK(IsDataByte(next)); |
100 DCHECK_NE(kSysEx, status_byte); | 100 DCHECK_NE(kSysEx, status_byte); |
101 const size_t target_len = GetMIDIMessageLength(status_byte); | 101 const size_t target_len = GetMidiMessageLength(status_byte); |
102 if (next_message_.size() < target_len) | 102 if (next_message_.size() < target_len) |
103 continue; | 103 continue; |
104 if (next_message_.size() == target_len) { | 104 if (next_message_.size() == target_len) { |
105 std::swap(*message, next_message_); | 105 std::swap(*message, next_message_); |
106 next_message_.clear(); | 106 next_message_.clear(); |
107 if (allow_running_status_) { | 107 if (allow_running_status_) { |
108 // Speculatively keep the status byte in case of running status. If this | 108 // Speculatively keep the status byte in case of running status. If this |
109 // assumption is not true, |next_message_| will be cleared anyway. | 109 // assumption is not true, |next_message_| will be cleared anyway. |
110 next_message_.push_back(status_byte); | 110 next_message_.push_back(status_byte); |
111 } | 111 } |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 NOTREACHED(); | 115 NOTREACHED(); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 } // namespace media | 119 } // namespace media |
OLD | NEW |