Deluge Firmware 1.3.0
Build date: 2025.06.05
Loading...
Searching...
No Matches
midi_root_complex.h
1/*
2 * Copyright © 2024 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "definitions_cxx.hpp"
21#include "io/midi/midi_device.h"
22
23enum class RootComplexType {
24 RC_DIN,
25 RC_USB_PERIPHERAL,
28 RC_USB_HOST,
29};
30
36class MIDIRootComplex {
37 class CableIterator {
38 private:
39 MIDIRootComplex& parent_;
40 size_t index_;
41
42 public:
43 CableIterator(const CableIterator&) = default;
44 CableIterator(CableIterator&&) = default;
45 CableIterator& operator=(const CableIterator&) = delete;
46 CableIterator& operator=(CableIterator&&) = delete;
47
48 CableIterator(MIDIRootComplex& parent, size_t index) : parent_{parent}, index_{index} {}
49
50 CableIterator& operator++() {
51 index_++;
52 return *this;
53 }
54
55 CableIterator operator++(int) {
56 auto pre = *this;
57 index_++;
58 return pre;
59 }
60
61 friend bool operator==(CableIterator const& a, CableIterator const& b) {
62 return &a.parent_ == &b.parent_ && a.index_ == b.index_;
63 };
64
65 friend bool operator!=(CableIterator const& a, CableIterator const& b) {
66 return &a.parent_ != &b.parent_ || a.index_ != b.index_;
67 };
68
69 MIDICable& operator*() { return *parent_.getCable(index_); }
70 MIDICable* operator->() { return parent_.getCable(index_); }
71 };
72
73 class CableSet {
74 public:
75 MIDIRootComplex& parent;
76
77 explicit CableSet(MIDIRootComplex& ccplex) : parent{ccplex} {}
78
79 CableIterator begin() { return CableIterator{parent, 0}; }
80 CableIterator end() { return CableIterator{parent, parent.getNumCables()}; }
81 };
82
83public:
84 MIDIRootComplex() = default;
85 MIDIRootComplex(const MIDIRootComplex&) = delete;
86 MIDIRootComplex(MIDIRootComplex&&) = delete;
87 MIDIRootComplex& operator=(const MIDIRootComplex&) = delete;
88 MIDIRootComplex& operator=(MIDIRootComplex&&) = delete;
89
90 virtual ~MIDIRootComplex() = default;
91
92 [[nodiscard]] virtual RootComplexType getType() const = 0;
93
94 [[nodiscard]] virtual size_t getNumCables() const = 0;
95 [[nodiscard]] virtual MIDICable* getCable(size_t cableIdx) = 0;
96
97 CableSet getCables() { return CableSet{*this}; }
98
100 virtual void flush() = 0;
101
103 [[nodiscard]] virtual Error poll() = 0;
104};
A MIDI cable connection. Stores all state specific to a given cable and its contained ports and chann...
Definition midi_device.h:94
Definition midi_root_complex.h:37
Definition midi_root_complex.h:73
virtual Error poll()=0
Poll the root complex, calling back in to the MIDI engine for any new messages.
virtual void flush()=0
Flush as much data as possible from any internal buffers to hardware queues.