Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRPN #213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

NRPN #213

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions JUCE/modules/juce_audio_basics/midi/juce_MidiMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,14 @@ MidiMessage MidiMessage::pitchWheel (const int channel, const int position) noex

bool MidiMessage::isController() const noexcept
{

return (getRawData()[0] & 0xf0) == 0xb0;
}
//User added, only use if it message is controller
bool MidiMessage::isNRPNController() const noexcept
{
return ((getRawData()[1] == 0x62) || (getRawData()[1] == 0x63) ||(getRawData()[1] == 0x06) ||(getRawData()[1] == 0x26) );
}

bool MidiMessage::isControllerOfType (const int controllerType) const noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions JUCE/modules/juce_audio_basics/midi/juce_MidiMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ class JUCE_API MidiMessage
@see getControllerNumber, getControllerValue, controllerEvent
*/
bool isController() const noexcept;

bool isNRPNController() const noexcept;

/** Returns the controller number of a controller message.

Expand Down
58 changes: 57 additions & 1 deletion hi_dsp/modules/MidiProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ void MidiProcessor::addHiseEventToBuffer(const HiseEvent &m)


}

/*void MidiProcessor::addHiseNRPNEventToBuffer(const HiseEvent &m)
{
ownerSynth->midiProcessorChain->addArtificialEvent(m);


}*/

ProcessorEditorBody *MidiProcessor::createEditor(ProcessorEditor *parentEditor)
{
Expand Down Expand Up @@ -125,6 +132,11 @@ bool MidiProcessorChain::setArtificialTimestamp(uint16 eventId, int newTimestamp

void MidiProcessorChain::renderNextHiseEventBuffer(HiseEventBuffer &buffer, int numSamples)
{
int parameterNumber = 0;

int nrpnValue = 0;


if (allNotesOffAtNextBuffer)
{
buffer.clear();
Expand All @@ -150,8 +162,52 @@ void MidiProcessorChain::renderNextHiseEventBuffer(HiseEventBuffer &buffer, int

jassert(buffer.timeStampsAreSorted());

//changed a lot - user added
while (HiseEvent* e = it.getNextEventPointer(true, false))
{
if (e->getType() == HiseEvent::Type::NRPNController)
{
switch(e->getControllerNumber())
{

//lsb
case 98:{
parameterNumber+= e->getControllerValue();
break;
}

//msb
case 99:{
parameterNumber += e->getControllerValue()*128;
break;
}

//lsb
case 38:{
nrpnValue = e->getControllerValue();
break;

}

//msb
case 6: {
HiseEvent nrpnEvent(*e);
if(nrpnValue)
nrpnValue += e->getControllerValue()*128;
else
nrpnValue = e->getControllerValue();
nrpnEvent.setParameterNumber(parameterNumber);
nrpnEvent.setNRPNValue(nrpnValue);
parameterNumber = 0;
nrpnValue = 0;
processHiseEvent(nrpnEvent);

break;

}
}
}
else
processHiseEvent(*e);
}

Expand Down Expand Up @@ -298,4 +354,4 @@ void MidiProcessorChain::MidiProcessorChainHandler::add(Processor *newProcessor,
notifyListeners(Listener::ProcessorAdded, newProcessor);
}

} // namespace hise
} // namespace hise
19 changes: 11 additions & 8 deletions hi_dsp/modules/ModulatorSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,15 +619,18 @@ void ModulatorSynth::handleHiseEvent(const HiseEvent& m)
else if (m.isController())
{
const int controllerNumber = m.getControllerNumber();

switch (controllerNumber)
{
case 0x40: handleSustainPedal(channel, m.getControllerValue() >= 64); break;
case 0x42: handleSostenutoPedal(channel, m.getControllerValue() >= 64); break;
case 0x43: handleSoftPedal(channel, m.getControllerValue() >= 64); break;
default: break;
}

if (!m.isNRPNController()){
switch (controllerNumber)
{
case 0x40: handleSustainPedal(channel, m.getControllerValue() >= 64); break;
case 0x42: handleSostenutoPedal(channel, m.getControllerValue() >= 64); break;
case 0x43: handleSoftPedal(channel, m.getControllerValue() >= 64); break;
default: break;
}
}
}

else if (m.isVolumeFade())
{
handleVolumeFade(m.getEventId(), m.getFadeTime(), m.getGainFactor());
Expand Down
5 changes: 4 additions & 1 deletion hi_scripting/scripting/HardcodedScriptProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void HardcodedScriptProcessor::processHiseEvent(HiseEvent &m)
case HiseEvent::Type::Aftertouch:
onController();
break;
case HiseEvent::Type::NRPNController:
onNRPNController();
break;
case HiseEvent::Type::TimerEvent:
{
if (m.getTimerIndex() == getIndexInChain())
Expand Down Expand Up @@ -181,4 +184,4 @@ Processor *HardcodedScriptFactoryType::createProcessor(int typeIndex, const Stri
return mp;
}

} // namespace hise
} // namespace hise
68 changes: 68 additions & 0 deletions hi_scripting/scripting/HardcodedScriptProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class HardcodedScriptProcessor: public ScriptBaseMidiProcessor

/** called if a cc message is processed. */
virtual void onController() {} ;

/** called if a cc message is processed. */
virtual void onNRPNController() {} ;

/** called periodically if the timer was started. */
virtual void onTimer(int /*offsetInBuffer*/) {};
Expand Down Expand Up @@ -319,6 +322,19 @@ class CCSwapper: public HardcodedScriptProcessor
Message.setControllerNumber(firstCC->getValue());
}
};

void onNRPNController() override
{
if(Message.getControllerNumber() == firstCC->getValue())
{
Message.setControllerNumber(secondCC->getValue());
}
else if(Message.getControllerNumber() == secondCC->getValue())
{
Message.setControllerNumber(firstCC->getValue());
}
};




Expand Down Expand Up @@ -571,6 +587,36 @@ class CCToNoteProcessor : public HardcodedScriptProcessor
}
}
};

void onNRPNController() override
{
if (lastNote != -1 && ((int)Message.getControllerNumber() == selectorValue))
{
if ((double)bypassButton->getValue() < 0.5)
{
updown = !updown;

if (!updown)
{

thisGroup = (int)floor(r.nextFloat() * (float)(rrAmount) / 2.0f);

while (thisGroup == lastGroup) thisGroup = (int)(floor(r.nextFloat() * (float)(rrAmount) / 2.0f));

lastGroup = thisGroup;
}

const int thisGroupNumber = thisGroup * 2 + (updown ? 1 : 0) + 1;

Sampler.setActiveGroup(thisGroupNumber);
}

if (lastNote != -1)
{
Synth.playNote(lastNote, Message.getControllerValue());
}
}
};

void onControl(ScriptingApi::Content::ScriptComponent * controllerThatWasMoved, var value) override
{
Expand Down Expand Up @@ -711,6 +757,23 @@ class ChannelFilterScriptProcessor : public HardcodedScriptProcessor,
}

};

void onNRPNController() override
{
if (mpeEnabled)
{
if (!mpeRange[Message.getChannel()-1])
Message.ignoreEvent(true);
}
else
{
if (Message.getChannel() != channel)
{
Message.ignoreEvent(true);
}
}

};

void onControl(ScriptingApi::Content::ScriptComponent *c, var value) override
{
Expand Down Expand Up @@ -788,6 +851,11 @@ class ChannelSetterScriptProcessor : public HardcodedScriptProcessor
{
Message.setChannel(channel);
};

void onNRPNController() override
{
Message.setChannel(channel);
};

void onControl(ScriptingApi::Content::ScriptComponent *, var value) override
{
Expand Down
1 change: 1 addition & 0 deletions hi_scripting/scripting/ScriptProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class ScriptBaseMidiProcessor: public MidiProcessor,
onNoteOn,
onNoteOff,
onController,
onNRPNController,
onTimer,
onControl,
numCallbacks
Expand Down
Loading