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