| 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" |
| 11 | 11 |
| 12 namespace media { | 12 namespace media { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const uint8 kSysEx = 0xf0; | 15 const uint8 kSysEx = 0xf0; |
| 16 const uint8 kEndOfSysEx = 0xf7; | 16 const uint8 kEndOfSysEx = 0xf7; |
| 17 | 17 |
| 18 bool IsDataByte(uint8 data) { | 18 bool IsDataByte(uint8 data) { |
| 19 return (data & 0x80) == 0; | 19 return (data & 0x80) == 0; |
| 20 } | 20 } |
| 21 | 21 |
| 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; | 27 return 0xf8 <= data; |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool IsSystemMessage(uint8 data) { |
| 31 return 0xf0 <= data; |
| 32 } |
| 33 |
| 30 } // namespace | 34 } // namespace |
| 31 | 35 |
| 32 MidiMessageQueue::MidiMessageQueue(bool allow_running_status) | 36 MidiMessageQueue::MidiMessageQueue(bool allow_running_status) |
| 33 : allow_running_status_(allow_running_status) {} | 37 : allow_running_status_(allow_running_status) {} |
| 34 | 38 |
| 35 MidiMessageQueue::~MidiMessageQueue() {} | 39 MidiMessageQueue::~MidiMessageQueue() {} |
| 36 | 40 |
| 37 void MidiMessageQueue::Add(const std::vector<uint8>& data) { | 41 void MidiMessageQueue::Add(const std::vector<uint8>& data) { |
| 38 queue_.insert(queue_.end(), data.begin(), data.end()); | 42 queue_.insert(queue_.end(), data.begin(), data.end()); |
| 39 } | 43 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 101 } |
| 98 | 102 |
| 99 DCHECK(IsDataByte(next)); | 103 DCHECK(IsDataByte(next)); |
| 100 DCHECK_NE(kSysEx, status_byte); | 104 DCHECK_NE(kSysEx, status_byte); |
| 101 const size_t target_len = GetMidiMessageLength(status_byte); | 105 const size_t target_len = GetMidiMessageLength(status_byte); |
| 102 if (next_message_.size() < target_len) | 106 if (next_message_.size() < target_len) |
| 103 continue; | 107 continue; |
| 104 if (next_message_.size() == target_len) { | 108 if (next_message_.size() == target_len) { |
| 105 std::swap(*message, next_message_); | 109 std::swap(*message, next_message_); |
| 106 next_message_.clear(); | 110 next_message_.clear(); |
| 107 if (allow_running_status_) { | 111 if (allow_running_status_ && !IsSystemMessage(status_byte)) { |
| 108 // Speculatively keep the status byte in case of running status. If this | 112 // Speculatively keep the status byte in case of running status. If this |
| 109 // assumption is not true, |next_message_| will be cleared anyway. | 113 // assumption is not true, |next_message_| will be cleared anyway. |
| 114 // Note that system common messages should reset the running status. |
| 110 next_message_.push_back(status_byte); | 115 next_message_.push_back(status_byte); |
| 111 } | 116 } |
| 112 return; | 117 return; |
| 113 } | 118 } |
| 114 | 119 |
| 115 NOTREACHED(); | 120 NOTREACHED(); |
| 116 } | 121 } |
| 117 } | 122 } |
| 118 | 123 |
| 119 } // namespace media | 124 } // namespace media |
| OLD | NEW |