1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2015 - ROLI Ltd.
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3
Details of these licenses can be found at: www.gnu.org/licenses
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.juce.com for more information.
==============================================================================
*/
#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED
class MainComponent : public Component,
private AudioIODeviceCallback,
private MidiInputCallback,
private MPESetupComponent::Listener
{
public:
//==============================================================================
MainComponent()
: audioSetupComp (audioDeviceManager, 0, 0, 0, 256, true, true, true, false),
zoneLayoutComp (colourPicker),
visualiserComp (colourPicker)
{
setLookAndFeel (&lookAndFeel);
setSize (880, 720);
audioDeviceManager.initialise (0, 2, 0, true, String(), 0);
audioDeviceManager.addMidiInputCallback (String(), this);
audioDeviceManager.addAudioCallback (this);
addAndMakeVisible (audioSetupComp);
addAndMakeVisible (MPESetupComp);
addAndMakeVisible (zoneLayoutComp);
addAndMakeVisible (visualiserViewport);
visualiserViewport.setScrollBarsShown (false, true);
visualiserViewport.setViewedComponent (&visualiserComp, false);
visualiserViewport.setViewPositionProportionately (0.5, 0.0);
MPESetupComp.addListener (&zoneLayoutComp);
MPESetupComp.addListener (this);
visualiserInstrument.addListener (&visualiserComp);
synth.setVoiceStealingEnabled (false);
for (int i = 0; i < 15; ++i)
synth.addVoice (new MPEDemoSynthVoice);
}
~MainComponent()
{
audioDeviceManager.removeMidiInputCallback (String(), this);
}
//==============================================================================
void resized() override
{
const int visualiserCompWidth = 2800;
const int visualiserCompHeight = 300;
const int zoneLayoutCompHeight = 60;
const float audioSetupCompRelativeWidth = 0.55f;
Rectangle<int> r (getLocalBounds());
visualiserViewport.setBounds (r.removeFromBottom (visualiserCompHeight));
visualiserComp.setBounds (Rectangle<int> (visualiserCompWidth,
visualiserViewport.getHeight() - visualiserViewport.getScrollBarThickness()));
zoneLayoutComp.setBounds (r.removeFromBottom (zoneLayoutCompHeight));
audioSetupComp.setBounds (r.removeFromLeft (proportionOfWidth (audioSetupCompRelativeWidth)));
MPESetupComp.setBounds (r);
}
//==============================================================================
void audioDeviceIOCallback (const float** /*inputChannelData*/, int /*numInputChannels*/,
float** outputChannelData, int numOutputChannels,
int numSamples) override
{
AudioBuffer<float> buffer (outputChannelData, numOutputChannels, numSamples);
buffer.clear();
MidiBuffer incomingMidi;
midiCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
synth.renderNextBlock (buffer, incomingMidi, 0, numSamples);
}
void audioDeviceAboutToStart (AudioIODevice* device) override
{
const double sampleRate = device->getCurrentSampleRate();
midiCollector.reset (sampleRate);
synth.setCurrentPlaybackSampleRate (sampleRate);
}
void audioDeviceStopped() override
{
}
private:
//==============================================================================
void handleIncomingMidiMessage (MidiInput* /*source*/,
const MidiMessage& message) override
{
visualiserInstrument.processNextMidiEvent (message);
midiCollector.addMessageToQueue (message);
}
//==============================================================================
void zoneAdded (MPEZone newZone) override
{
MidiOutput* midiOutput = audioDeviceManager.getDefaultMidiOutput();
if (midiOutput != nullptr)
midiOutput->sendBlockOfMessagesNow (MPEMessages::addZone (newZone));
zoneLayout.addZone (newZone);
visualiserInstrument.setZoneLayout (zoneLayout);
synth.setZoneLayout (zoneLayout);
colourPicker.setZoneLayout (zoneLayout);
}
void allZonesCleared() override
{
MidiOutput* midiOutput = audioDeviceManager.getDefaultMidiOutput();
if (midiOutput != nullptr)
midiOutput->sendBlockOfMessagesNow (MPEMessages::clearAllZones());
zoneLayout.clearAllZones();
visualiserInstrument.setZoneLayout (zoneLayout);
synth.setZoneLayout (zoneLayout);
colourPicker.setZoneLayout (zoneLayout);
}
void legacyModeChanged (bool legacyModeShouldBeEnabled, int pitchbendRange, Range<int> channelRange) override
{
colourPicker.setLegacyModeEnabled (legacyModeShouldBeEnabled);
if (legacyModeShouldBeEnabled)
{
synth.enableLegacyMode (pitchbendRange, channelRange);
visualiserInstrument.enableLegacyMode (pitchbendRange, channelRange);
}
else
{
synth.setZoneLayout (zoneLayout);
visualiserInstrument.setZoneLayout (zoneLayout);
}
}
void voiceStealingEnabledChanged (bool voiceStealingEnabled) override
{
synth.setVoiceStealingEnabled (voiceStealingEnabled);
}
void numberOfVoicesChanged (int numberOfVoices) override
{
if (numberOfVoices < synth.getNumVoices())
synth.reduceNumVoices (numberOfVoices);
else
while (synth.getNumVoices() < numberOfVoices)
synth.addVoice (new MPEDemoSynthVoice);
}
//==============================================================================
LookAndFeel_V3 lookAndFeel;
AudioDeviceManager audioDeviceManager;
MPEZoneLayout zoneLayout;
ZoneColourPicker colourPicker;
AudioDeviceSelectorComponent audioSetupComp;
MPESetupComponent MPESetupComp;
ZoneLayoutComponent zoneLayoutComp;
Visualiser visualiserComp;
Viewport visualiserViewport;
MPEInstrument visualiserInstrument;
MPESynthesiser synth;
MidiMessageCollector midiCollector;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};
#endif // MAINCOMPONENT_H_INCLUDED
|