1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Message.h Sun May 11 00:30:03 2025 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/**
1.5 + * djm-fix
1.6 + * Copyright © 2025 František Kučera (Frantovo.cz, GlobalCode.info)
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, version 3 of the License.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.19 + */
1.20 +
1.21 +#pragma once
1.22 +
1.23 +#include <stdint.h>
1.24 +#include <vector>
1.25 +#include <string>
1.26 +#include <ostream>
1.27 +
1.28 +enum class MessageType : uint8_t {
1.29 + /** device sends: greeting message */
1.30 + D11_GREETING = 0x11,
1.31 +
1.32 + /** host sends: seed1 */
1.33 + H12_SEED1 = 0x12,
1.34 +
1.35 + /** device sends: hash1 and seed2 */
1.36 + D13_HASH1_SEED2 = 0x13,
1.37 +
1.38 + /** host sends: hash2 */
1.39 + H14_HASH2 = 0x14,
1.40 +
1.41 + /** device sends: confirmation of successful handshake */
1.42 + D15_CONFIRMATION = 0x15,
1.43 +};
1.44 +
1.45 +enum class FieldType : uint8_t {
1.46 + /** manufacturer name */
1.47 + F01 = 0x01,
1.48 + /** product name */
1.49 + F02 = 0x02,
1.50 + /** seed1 from host | seed2 from device */
1.51 + F03 = 0x03,
1.52 + /** hash2 from host | hash1 from device */
1.53 + F04 = 0x04,
1.54 + /** seed3 from device */
1.55 + F05 = 0x05,
1.56 +};
1.57 +
1.58 +class Field {
1.59 +public:
1.60 + FieldType type;
1.61 + std::vector<uint8_t> data;
1.62 +
1.63 + Field(FieldType type, std::vector<uint8_t> data) : type(type), data(data) {
1.64 + }
1.65 +
1.66 + virtual ~Field() = default;
1.67 +};
1.68 +
1.69 +/**
1.70 + * Object representation of a raw MIDI message.
1.71 + * Is either a result of parsing a raw message by MessageCodec, or constructed
1.72 + * in the application to be serialized in MessageCodec to a raw message.
1.73 + */
1.74 +class Message {
1.75 +public:
1.76 + MessageType type;
1.77 + /** 0x17 for DJM-250MK2 and 0x34 for V10 (maybe not a version) */
1.78 + uint8_t version;
1.79 + std::vector<Field> fields;
1.80 +
1.81 + Message(MessageType type, uint8_t version, std::vector<Field> fields) :
1.82 + type(type), version(version), fields(fields) {
1.83 + }
1.84 +
1.85 + virtual ~Message() = default;
1.86 +
1.87 + std::string toString() const;
1.88 +
1.89 + std::vector<Field> findFields(FieldType type);
1.90 +
1.91 +};