NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
sysex.h
Go to the documentation of this file.
1/*
2 * NiCMidi - A C++ Class Library for MIDI
3 *
4 * Copyright (C) 2004 J.D. Koftinoff Software, Ltd.
5 * www.jdkoftinoff.com jeffk@jdkoftinoff.com
6 * Copyright (C) 2010 V.R.Madgazin
7 * www.vmgames.com vrm@vmgames.com
8 * Copyright (C) 2021, 2022 Nicola Cassetta
9 * https://github.com/ncassetta/NiCMidi
10 *
11 * This file is part of NiCMidi.
12 *
13 * NiCMidi is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as
15 * published by the Free Software Foundation, either version 3 of
16 * the License, or (at your option) any later version.
17 *
18 * NiCMidi is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with NiCMidi. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27
30
31
32#ifndef _NICMIDI_SYSEX_H
33#define _NICMIDI_SYSEX_H
34
35#include "midi.h"
36#include <vector>
37#include <cstring> // for memcmp()
38
39
46 public:
49 MIDISystemExclusive(unsigned int len = 0);
56 MIDISystemExclusive(const unsigned char *buf, unsigned int len);
63 bool operator== (const MIDISystemExclusive &se) const;
64
66 void Clear() { buffer.clear(); chk_sum = 0; }
68 void ClearChecksum() { chk_sum = 0; }
70 unsigned char GetChecksum() const { return (unsigned char)(chk_sum & 0x7f); }
72 int GetLength() const { return buffer.size(); }
74 unsigned char GetData(int i) const { return buffer[i]; }
76 //unsigned char* GetBuffer() { return buffer; }
77 const unsigned char* GetBuffer() const { return buffer.data(); }
79 bool IsGMReset() const;
81 bool IsGSReset() const;
83 bool IsXGReset() const;
85 void PutSysByte(unsigned char b) { buffer.push_back(b); }
87 void PutByte(unsigned char b) { PutSysByte(b); chk_sum += b; }
93 void PutNibblizedByteLH(unsigned char b)
94 { PutByte((unsigned char)(b & 0xf)); PutByte((unsigned char)(b >> 4)); }
96 void PutNibblizedByteHL(unsigned char b)
97 { PutByte((unsigned char)(b >> 4)); PutByte((unsigned char)(b & 0xf)); }
99 void PutChecksum() { PutByte((unsigned char)(chk_sum & 0x7f)); }
100
101 protected:
103 std::vector<unsigned char> buffer;
104 unsigned char chk_sum;
105
106 static const unsigned char GMReset_data[];
107 static const unsigned char GSReset_data[];
108 static const unsigned char XGReset_data[];
109 static const int GMReset_len = 6;
110 static const int GSReset_len = 11;
111 static const int XGReset_len = 9;
113};
114
115
116
117#endif
Stores a buffer of MIDI data bytes in a std::vector, plus a byte for the checksum.
Definition: sysex.h:45
void ClearChecksum()
Resets the checksum to 0.
Definition: sysex.h:68
void PutChecksum()
Appends the checksum to the buffer.
Definition: sysex.h:99
MIDISystemExclusive(unsigned int len=0)
Creates a new object initially empty.
void PutNibblizedByteLH(unsigned char b)
Appends two bytes, containing the low (1st) and the high nibble of b. Adds them to the checksum.
Definition: sysex.h:93
unsigned char GetData(int i) const
Returns the i-th byte in the buffer.
Definition: sysex.h:74
const unsigned char * GetBuffer() const
Returns a pointer to the data buffer.
Definition: sysex.h:77
void PutByte(unsigned char b)
Appends a byte to the buffer, adding it to checksum.
Definition: sysex.h:87
MIDISystemExclusive & operator=(const MIDISystemExclusive &se)
The assignment operator.
MIDISystemExclusive(const MIDISystemExclusive &e)
The copy constructor.
MIDISystemExclusive(const unsigned char *buf, unsigned int len)
Creates a new object from the given buffer of bytes.
void PutNibblizedByteHL(unsigned char b)
Appends two bytes, containing the high (1st) and the low nibble of b. Adds them to the checksum.
Definition: sysex.h:96
bool IsXGReset() const
Returns true if the buffer contains a XG Reset sysex message.
int GetLength() const
Returns the number of data bytes stored in the buffer.
Definition: sysex.h:72
bool IsGMReset() const
Returns true if the buffer contains a GM Reset sysex message.
bool operator==(const MIDISystemExclusive &se) const
The equal operator compares the data buffer and the checksum.
bool IsGSReset() const
Returns true if the buffer contains a GS Reset sysex message.
virtual ~MIDISystemExclusive()
The destructor.
Definition: sysex.h:58
void Clear()
Resets the buffer to 0 length data and the checksum to 0.
Definition: sysex.h:66
void PutEOX()
Appends a System exclusive End byte (0xF7) to the buffer, without affecting the checksum.
Definition: sysex.h:91
void PutSysByte(unsigned char b)
Appends a byte to the buffer, without adding it to checksum.
Definition: sysex.h:85
unsigned char GetChecksum() const
Returns the checksum.
Definition: sysex.h:70
void PutEXC()
Appends a System exclusive Start byte (0xF0) to the buffer, without affecting the checksum.
Definition: sysex.h:89
@ SYSEX_START
Start of a sysex.
Definition: midi.h:101
@ SYSEX_END
End of a sysex.
Definition: midi.h:106
Contains the MIDI values enumerations (to have readable values instead of hexadecimal values) and som...