message_util.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_MIDI_MESSAGE_UTIL_H_
  5. #define MEDIA_MIDI_MESSAGE_UTIL_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <vector>
  9. #include "media/midi/midi_export.h"
  10. namespace midi {
  11. // Returns the length of a MIDI message in bytes. Never returns 4 or greater.
  12. // Returns 0 if |status_byte| is:
  13. // - not a valid status byte, namely data byte.
  14. // - MIDI System Exclusive message.
  15. // - End of System Exclusive message.
  16. // - Reserved System Common Message (0xf4, 0xf5)
  17. MIDI_EXPORT size_t GetMessageLength(uint8_t status_byte);
  18. // Checks if the specified byte is a valid data byte.
  19. MIDI_EXPORT bool IsDataByte(uint8_t data);
  20. // Checks if the specified byte is a valid system real time message.
  21. MIDI_EXPORT bool IsSystemRealTimeMessage(uint8_t data);
  22. // Checks if the specified byte is a valid system message.
  23. MIDI_EXPORT bool IsSystemMessage(uint8_t data);
  24. // Checks if |data| fulfills the requirements of MidiOutput.send API that is
  25. // defined in the Web MIDI spec.
  26. // - |data| must be any number of complete MIDI messages (data abbreviation
  27. // called "running status" is disallowed).
  28. // - 1-byte MIDI realtime messages can be placed at any position of |data|.
  29. MIDI_EXPORT bool IsValidWebMIDIData(const std::vector<uint8_t>& data);
  30. const uint8_t kSysExByte = 0xf0;
  31. const uint8_t kEndOfSysExByte = 0xf7;
  32. const uint8_t kSysMessageBitMask = 0xf0;
  33. const uint8_t kSysMessageBitPattern = 0xf0;
  34. const uint8_t kSysRTMessageBitMask = 0xf8;
  35. const uint8_t kSysRTMessageBitPattern = 0xf8;
  36. } // namespace midi
  37. #endif // MEDIA_MIDI_MESSAGE_UTIL_H_