Message.h
author František Kučera <franta-hg@frantovo.cz>
Sun, 01 Jun 2025 13:18:10 +0200
branchv_0
changeset 20 a08e30243b95
parent 19 4ed672cecc25
permissions -rw-r--r--
Added tag v0.1 for changeset 334b727f7516
franta-hg@18
     1
/**
franta-hg@18
     2
 * djm-fix
franta-hg@18
     3
 * Copyright © 2025 František Kučera (Frantovo.cz, GlobalCode.info)
franta-hg@18
     4
 *
franta-hg@18
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@18
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@18
     7
 * the Free Software Foundation, version 3 of the License.
franta-hg@18
     8
 *
franta-hg@18
     9
 * This program is distributed in the hope that it will be useful,
franta-hg@18
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@18
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@18
    12
 * GNU General Public License for more details.
franta-hg@18
    13
 *
franta-hg@18
    14
 * You should have received a copy of the GNU General Public License
franta-hg@18
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@18
    16
 */
franta-hg@18
    17
franta-hg@18
    18
#pragma once
franta-hg@18
    19
franta-hg@18
    20
#include <stdint.h>
franta-hg@18
    21
#include <vector>
franta-hg@18
    22
#include <string>
franta-hg@18
    23
#include <ostream>
franta-hg@18
    24
franta-hg@18
    25
enum class MessageType : uint8_t {
franta-hg@18
    26
	/** device sends: greeting message */
franta-hg@18
    27
	D11_GREETING = 0x11,
franta-hg@18
    28
franta-hg@18
    29
	/** host sends: seed1 */
franta-hg@18
    30
	H12_SEED1 = 0x12,
franta-hg@18
    31
franta-hg@18
    32
	/** device sends: hash1 and seed2 */
franta-hg@18
    33
	D13_HASH1_SEED2 = 0x13,
franta-hg@18
    34
franta-hg@18
    35
	/** host sends: hash2 */
franta-hg@18
    36
	H14_HASH2 = 0x14,
franta-hg@18
    37
franta-hg@18
    38
	/** device sends: confirmation of successful handshake */
franta-hg@18
    39
	D15_CONFIRMATION = 0x15,
franta-hg@18
    40
};
franta-hg@18
    41
franta-hg@18
    42
enum class FieldType : uint8_t {
franta-hg@18
    43
	/** manufacturer name */
franta-hg@18
    44
	F01 = 0x01,
franta-hg@18
    45
	/** product name */
franta-hg@18
    46
	F02 = 0x02,
franta-hg@18
    47
	/** seed1 from host | seed2 from device */
franta-hg@18
    48
	F03 = 0x03,
franta-hg@18
    49
	/** hash2 from host | hash1 from device */
franta-hg@18
    50
	F04 = 0x04,
franta-hg@18
    51
	/** seed3 from device */
franta-hg@18
    52
	F05 = 0x05,
franta-hg@18
    53
};
franta-hg@18
    54
franta-hg@18
    55
class Field {
franta-hg@18
    56
public:
franta-hg@18
    57
	FieldType type;
franta-hg@18
    58
	std::vector<uint8_t> data;
franta-hg@18
    59
franta-hg@18
    60
	Field(FieldType type, std::vector<uint8_t> data) : type(type), data(data) {
franta-hg@18
    61
	}
franta-hg@18
    62
franta-hg@18
    63
	virtual ~Field() = default;
franta-hg@18
    64
};
franta-hg@18
    65
franta-hg@18
    66
/**
franta-hg@18
    67
 * Object representation of a raw MIDI message.
franta-hg@18
    68
 * Is either a result of parsing a raw message by MessageCodec, or constructed
franta-hg@18
    69
 * in the application to be serialized in MessageCodec to a raw message.
franta-hg@18
    70
 */
franta-hg@18
    71
class Message {
franta-hg@18
    72
public:
franta-hg@18
    73
	MessageType type;
franta-hg@19
    74
	/** 0x17 for DJM-250MK2 and 0x34 for V10 */
franta-hg@19
    75
	uint8_t model;
franta-hg@18
    76
	std::vector<Field> fields;
franta-hg@18
    77
franta-hg@19
    78
	Message(MessageType type, uint8_t model, std::vector<Field> fields) :
franta-hg@19
    79
			type(type), model(model), fields(fields) {
franta-hg@18
    80
	}
franta-hg@18
    81
franta-hg@18
    82
	virtual ~Message() = default;
franta-hg@18
    83
franta-hg@18
    84
	std::string toString() const;
franta-hg@18
    85
franta-hg@18
    86
	std::vector<Field> findFields(FieldType type);
franta-hg@18
    87
franta-hg@18
    88
};