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