MCPcopy Create free account
hub / github.com/christophhart/HISE / internalAddNoteOn

Method internalAddNoteOn

hi_scripting/scripting/api/ScriptingApi.cpp:6186–6250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6184}
6185
6186int ScriptingApi::Synth::internalAddNoteOn(int channel, int noteNumber, int velocity, int timeStampSamples, int startOffset)
6187{
6188 if (channel > 0 && channel <= 16)
6189 {
6190 if (noteNumber >= 0 && noteNumber < 127)
6191 {
6192 if (velocity >= 0 && velocity <= 127)
6193 {
6194 if (timeStampSamples >= 0)
6195 {
6196 if (parentMidiProcessor != nullptr)
6197 {
6198 HiseEvent m = HiseEvent(HiseEvent::Type::NoteOn, (uint8)noteNumber, (uint8)velocity, (uint8)channel);
6199
6200
6201#if HISE_USE_BACKWARDS_COMPATIBLE_TIMESTAMPS
6202
6203 if (getProcessor()->getMainController()->getKillStateHandler().getCurrentThread() == MainController::KillStateHandler::TargetThread::AudioThread)
6204 {
6205 // Apparently there was something wrong with the timestamp calculation.
6206 // This restores the old behaviour by removing one block from the timestamps.
6207 // By default, it's turned off, but you can enable it if you need backwards
6208 // compatibility with older patches...
6209 int blocksize = parentMidiProcessor->getMainController()->getBufferSizeForCurrentBlock();
6210 timeStampSamples = jmax<int>(0, timeStampSamples - blocksize);
6211 }
6212#endif
6213
6214 if (auto ce = parentMidiProcessor->getCurrentHiseEvent())
6215 {
6216 m.setTimeStamp((int)ce->getTimeStamp() + timeStampSamples);
6217 }
6218 else
6219 {
6220 m.setTimeStamp(timeStampSamples);
6221 }
6222
6223 if (startOffset > UINT16_MAX)
6224 reportScriptError("Max start offset is 65536 (2^16)");
6225
6226 m.setStartOffset((uint16)startOffset);
6227
6228 m.setArtificial();
6229
6230 parentMidiProcessor->getMainController()->getEventHandler().pushArtificialNoteOn(m);
6231
6232 if (messageObject != nullptr)
6233 messageObject->pushArtificialNoteOn(m);
6234
6235 parentMidiProcessor->addHiseEventToBuffer(m);
6236
6237 return m.getEventId();
6238 }
6239 else reportScriptError("Only valid in MidiProcessors");
6240 }
6241 else reportScriptError("Timestamp must be >= 0");
6242 }
6243 else reportScriptError("Velocity must be between 0 and 127");

Callers

nothing calls this directly

Calls 13

HiseEventFunction · 0.85
getProcessorFunction · 0.85
getCurrentHiseEventMethod · 0.80
setTimeStampMethod · 0.80
getTimeStampMethod · 0.80
setArtificialMethod · 0.80
addHiseEventToBufferMethod · 0.80
getCurrentThreadMethod · 0.45
getMainControllerMethod · 0.45
setStartOffsetMethod · 0.45
pushArtificialNoteOnMethod · 0.45

Tested by

no test coverage detected