OpenShot Audio Library | OpenShotAudio 0.4.0
juce_MPEUtils.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
38{
39public:
45
50 MPEChannelAssigner (Range<int> channelRange = Range<int> (1, 17));
51
64 int findMidiChannelForNewNote (int noteNumber) noexcept;
65
69 int findMidiChannelForExistingNote (int initialNoteOnNumber) noexcept;
70
77 void noteOff (int noteNumber, int midiChannel = -1);
78
80 void allNotesOff();
81
82private:
83 bool isLegacy = false;
84 std::unique_ptr<MPEZoneLayout::Zone> zone;
85 int channelIncrement, numChannels, firstChannel, lastChannel, midiChannelLastAssigned;
86
87 //==============================================================================
88 struct MidiChannel
89 {
90 Array<int> notes;
91 int lastNotePlayed = -1;
92 bool isFree() const noexcept { return notes.isEmpty(); }
93 };
94 std::array<MidiChannel, 17> midiChannels;
95
96 //==============================================================================
97 int findMidiChannelPlayingClosestNonequalNote (int noteNumber) noexcept;
98};
99
100//==============================================================================
108{
109public:
111 static const uint32 notMPE = 0;
112
115
116 //==============================================================================
126 void remapMidiChannelIfNeeded (MidiMessage& message, uint32 mpeSourceID) noexcept;
127
128 //==============================================================================
130 void reset() noexcept;
131
133 void clearChannel (int channel) noexcept;
134
136 void clearSource (uint32 mpeSourceID);
137
138private:
139 MPEZoneLayout::Zone zone;
140
141 int channelIncrement;
142 int firstChannel, lastChannel;
143
144 uint32 sourceAndChannel[17];
145 uint32 lastUsed[17];
146 uint32 counter = 0;
147
148 //==============================================================================
149 bool applyRemapIfExisting (int channel, uint32 sourceAndChannelID, MidiMessage& m) noexcept;
150 int getBestChanToReuse() const noexcept;
151
152 void zeroArrays();
153
154 //==============================================================================
155 bool messageIsNoteData (const MidiMessage& m) { return (*m.getRawData() & 0xf0) != 0xf0; }
156};
157
158} // namespace juce
bool isEmpty() const noexcept
Definition: juce_Array.h:222
int findMidiChannelForExistingNote(int initialNoteOnNumber) noexcept
MPEChannelAssigner(MPEZoneLayout::Zone zoneToUse)
int findMidiChannelForNewNote(int noteNumber) noexcept
void noteOff(int noteNumber, int midiChannel=-1)
void remapMidiChannelIfNeeded(MidiMessage &message, uint32 mpeSourceID) noexcept
static const uint32 notMPE
void clearChannel(int channel) noexcept
void clearSource(uint32 mpeSourceID)
MPEChannelRemapper(MPEZoneLayout::Zone zoneToRemap)