53 |
|
|
54 |
Event e = m_vm->m_event->cause; // copy to get fragment time for "now" |
Event e = m_vm->m_event->cause; // copy to get fragment time for "now" |
55 |
e.Init(); // clear IDs |
e.Init(); // clear IDs |
56 |
e.Type = Event::type_note_on; |
e.Type = Event::type_play_note; |
57 |
e.Param.Note.Key = note; |
e.Param.Note.Key = note; |
58 |
e.Param.Note.Velocity = velocity; |
e.Param.Note.Velocity = velocity; |
59 |
// make this new note dependent to the life time of the original note |
// make this new note dependent to the life time of the original note |
67 |
|
|
68 |
const note_id_t id = pEngineChannel->ScheduleNoteMicroSec(&e, 0); |
const note_id_t id = pEngineChannel->ScheduleNoteMicroSec(&e, 0); |
69 |
|
|
70 |
// if a duration is supplied (and note-on event was scheduled |
// if a duration is supplied (and play-note event was scheduled |
71 |
// successfully above), then schedule a subsequent note-off event |
// successfully above), then schedule a subsequent stop-note event |
72 |
if (id && duration > 0) { |
if (id && duration > 0) { |
73 |
e.Type = Event::type_note_off; |
e.Type = Event::type_stop_note; |
74 |
|
e.Param.Note.ID = id; |
75 |
e.Param.Note.Velocity = 127; |
e.Param.Note.Velocity = 127; |
76 |
pEngineChannel->ScheduleEventMicroSec(&e, duration); |
pEngineChannel->ScheduleEventMicroSec(&e, duration); |
77 |
} |
} |
215 |
Event e = pNote->cause; |
Event e = pNote->cause; |
216 |
e.Init(); // clear IDs |
e.Init(); // clear IDs |
217 |
e.CopyTimeFrom(m_vm->m_event->cause); // set fragment time for "now" |
e.CopyTimeFrom(m_vm->m_event->cause); // set fragment time for "now" |
218 |
e.Type = Event::type_note_off; |
e.Type = Event::type_stop_note; |
219 |
|
e.Param.Note.ID = id.noteID(); |
220 |
|
e.Param.Note.Key = pNote->hostKey; |
221 |
e.Param.Note.Velocity = velocity; |
e.Param.Note.Velocity = velocity; |
222 |
|
|
223 |
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
233 |
Event e = pNote->cause; |
Event e = pNote->cause; |
234 |
e.Init(); // clear IDs |
e.Init(); // clear IDs |
235 |
e.CopyTimeFrom(m_vm->m_event->cause); // set fragment time for "now" |
e.CopyTimeFrom(m_vm->m_event->cause); // set fragment time for "now" |
236 |
e.Type = Event::type_note_off; |
e.Type = Event::type_stop_note; |
237 |
|
e.Param.Note.ID = id.noteID(); |
238 |
|
e.Param.Note.Key = pNote->hostKey; |
239 |
e.Param.Note.Velocity = velocity; |
e.Param.Note.Velocity = velocity; |
240 |
|
|
241 |
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
605 |
|
|
606 |
return successResult(); |
return successResult(); |
607 |
} |
} |
608 |
|
|
609 |
|
#define VM_FILTER_PAR_MAX_VALUE 1000000 |
610 |
|
|
611 |
|
// change_cutoff() function |
612 |
|
|
613 |
|
InstrumentScriptVMFunction_change_cutoff::InstrumentScriptVMFunction_change_cutoff(InstrumentScriptVM* parent) |
614 |
|
: m_vm(parent) |
615 |
|
{ |
616 |
|
} |
617 |
|
|
618 |
|
bool InstrumentScriptVMFunction_change_cutoff::acceptsArgType(int iArg, ExprType_t type) const { |
619 |
|
if (iArg == 0) |
620 |
|
return type == INT_EXPR || type == INT_ARR_EXPR; |
621 |
|
else |
622 |
|
return INT_EXPR; |
623 |
|
} |
624 |
|
|
625 |
|
VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) { |
626 |
|
int cutoff = args->arg(1)->asInt()->evalInt(); |
627 |
|
if (cutoff > VM_FILTER_PAR_MAX_VALUE) { |
628 |
|
wrnMsg("change_cutoff(): argument 2 may not be larger than 1000000"); |
629 |
|
cutoff = VM_FILTER_PAR_MAX_VALUE; |
630 |
|
} else if (cutoff < 0) { |
631 |
|
wrnMsg("change_cutoff(): argument 2 may not be negative"); |
632 |
|
cutoff = 0; |
633 |
|
} |
634 |
|
|
635 |
|
AbstractEngineChannel* pEngineChannel = |
636 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
637 |
|
|
638 |
|
if (args->arg(0)->exprType() == INT_EXPR) { |
639 |
|
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
640 |
|
if (!id) { |
641 |
|
wrnMsg("change_cutoff(): note ID for argument 1 may not be zero"); |
642 |
|
return successResult(); |
643 |
|
} |
644 |
|
if (!id.isNoteID()) { |
645 |
|
wrnMsg("change_cutoff(): argument 1 is not a note ID"); |
646 |
|
return successResult(); |
647 |
|
} |
648 |
|
|
649 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
650 |
|
if (!pNote) return successResult(); |
651 |
|
|
652 |
|
const float fCutoff = float(cutoff) / float(VM_FILTER_PAR_MAX_VALUE); |
653 |
|
|
654 |
|
Event e = m_vm->m_event->cause; // copy to get fragment time for "now" |
655 |
|
e.Init(); // clear IDs |
656 |
|
e.Type = Event::type_note_synth_param; |
657 |
|
e.Param.NoteSynthParam.NoteID = id.noteID(); |
658 |
|
e.Param.NoteSynthParam.Type = Event::synth_param_cutoff; |
659 |
|
e.Param.NoteSynthParam.Delta = fCutoff; |
660 |
|
e.Param.NoteSynthParam.Relative = false; |
661 |
|
|
662 |
|
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
663 |
|
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
664 |
|
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
665 |
|
for (int i = 0; i < ids->arraySize(); ++i) { |
666 |
|
const ScriptID id = ids->evalIntElement(i); |
667 |
|
if (!id || !id.isNoteID()) continue; |
668 |
|
|
669 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
670 |
|
if (!pNote) continue; |
671 |
|
|
672 |
|
const float fCutoff = float(cutoff) / float(VM_FILTER_PAR_MAX_VALUE); |
673 |
|
|
674 |
|
Event e = m_vm->m_event->cause; // copy to get fragment time for "now" |
675 |
|
e.Init(); // clear IDs |
676 |
|
e.Type = Event::type_note_synth_param; |
677 |
|
e.Param.NoteSynthParam.NoteID = id.noteID(); |
678 |
|
e.Param.NoteSynthParam.Type = Event::synth_param_cutoff; |
679 |
|
e.Param.NoteSynthParam.Delta = fCutoff; |
680 |
|
e.Param.NoteSynthParam.Relative = false; |
681 |
|
|
682 |
|
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
683 |
|
} |
684 |
|
} |
685 |
|
|
686 |
|
return successResult(); |
687 |
|
} |
688 |
|
|
689 |
|
// change_reso() function |
690 |
|
|
691 |
|
InstrumentScriptVMFunction_change_reso::InstrumentScriptVMFunction_change_reso(InstrumentScriptVM* parent) |
692 |
|
: m_vm(parent) |
693 |
|
{ |
694 |
|
} |
695 |
|
|
696 |
|
bool InstrumentScriptVMFunction_change_reso::acceptsArgType(int iArg, ExprType_t type) const { |
697 |
|
if (iArg == 0) |
698 |
|
return type == INT_EXPR || type == INT_ARR_EXPR; |
699 |
|
else |
700 |
|
return INT_EXPR; |
701 |
|
} |
702 |
|
|
703 |
|
VMFnResult* InstrumentScriptVMFunction_change_reso::exec(VMFnArgs* args) { |
704 |
|
int resonance = args->arg(1)->asInt()->evalInt(); |
705 |
|
if (resonance > VM_FILTER_PAR_MAX_VALUE) { |
706 |
|
wrnMsg("change_reso(): argument 2 may not be larger than 1000000"); |
707 |
|
resonance = VM_FILTER_PAR_MAX_VALUE; |
708 |
|
} else if (resonance < 0) { |
709 |
|
wrnMsg("change_reso(): argument 2 may not be negative"); |
710 |
|
resonance = 0; |
711 |
|
} |
712 |
|
|
713 |
|
AbstractEngineChannel* pEngineChannel = |
714 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
715 |
|
|
716 |
|
if (args->arg(0)->exprType() == INT_EXPR) { |
717 |
|
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
718 |
|
if (!id) { |
719 |
|
wrnMsg("change_reso(): note ID for argument 1 may not be zero"); |
720 |
|
return successResult(); |
721 |
|
} |
722 |
|
if (!id.isNoteID()) { |
723 |
|
wrnMsg("change_reso(): argument 1 is not a note ID"); |
724 |
|
return successResult(); |
725 |
|
} |
726 |
|
|
727 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
728 |
|
if (!pNote) return successResult(); |
729 |
|
|
730 |
|
const float fResonance = float(resonance) / float(VM_FILTER_PAR_MAX_VALUE); |
731 |
|
|
732 |
|
Event e = m_vm->m_event->cause; // copy to get fragment time for "now" |
733 |
|
e.Init(); // clear IDs |
734 |
|
e.Type = Event::type_note_synth_param; |
735 |
|
e.Param.NoteSynthParam.NoteID = id.noteID(); |
736 |
|
e.Param.NoteSynthParam.Type = Event::synth_param_resonance; |
737 |
|
e.Param.NoteSynthParam.Delta = fResonance; |
738 |
|
e.Param.NoteSynthParam.Relative = false; |
739 |
|
|
740 |
|
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
741 |
|
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
742 |
|
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
743 |
|
for (int i = 0; i < ids->arraySize(); ++i) { |
744 |
|
const ScriptID id = ids->evalIntElement(i); |
745 |
|
if (!id || !id.isNoteID()) continue; |
746 |
|
|
747 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
748 |
|
if (!pNote) continue; |
749 |
|
|
750 |
|
const float fResonance = float(resonance) / float(VM_FILTER_PAR_MAX_VALUE); |
751 |
|
|
752 |
|
Event e = m_vm->m_event->cause; // copy to get fragment time for "now" |
753 |
|
e.Init(); // clear IDs |
754 |
|
e.Type = Event::type_note_synth_param; |
755 |
|
e.Param.NoteSynthParam.NoteID = id.noteID(); |
756 |
|
e.Param.NoteSynthParam.Type = Event::synth_param_resonance; |
757 |
|
e.Param.NoteSynthParam.Delta = fResonance; |
758 |
|
e.Param.NoteSynthParam.Relative = false; |
759 |
|
|
760 |
|
pEngineChannel->ScheduleEventMicroSec(&e, 0); |
761 |
|
} |
762 |
|
} |
763 |
|
|
764 |
|
return successResult(); |
765 |
|
} |
766 |
|
|
767 |
|
// event_status() function |
768 |
|
|
769 |
|
InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent) |
770 |
|
: m_vm(parent) |
771 |
|
{ |
772 |
|
} |
773 |
|
|
774 |
|
VMFnResult* InstrumentScriptVMFunction_event_status::exec(VMFnArgs* args) { |
775 |
|
AbstractEngineChannel* pEngineChannel = |
776 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
777 |
|
|
778 |
|
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
779 |
|
if (!id) { |
780 |
|
wrnMsg("event_status(): note ID for argument 1 may not be zero"); |
781 |
|
return successResult(EVENT_STATUS_INACTIVE); |
782 |
|
} |
783 |
|
if (!id.isNoteID()) { |
784 |
|
wrnMsg("event_status(): argument 1 is not a note ID"); |
785 |
|
return successResult(EVENT_STATUS_INACTIVE); |
786 |
|
} |
787 |
|
|
788 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
789 |
|
return successResult(pNote ? EVENT_STATUS_NOTE_QUEUE : EVENT_STATUS_INACTIVE); |
790 |
|
} |
791 |
|
|
792 |
|
// wait() function (overrides core wait() implementation) |
793 |
|
|
794 |
|
InstrumentScriptVMFunction_wait::InstrumentScriptVMFunction_wait(InstrumentScriptVM* parent) |
795 |
|
: CoreVMFunction_wait(parent) |
796 |
|
{ |
797 |
|
} |
798 |
|
|
799 |
|
VMFnResult* InstrumentScriptVMFunction_wait::exec(VMFnArgs* args) { |
800 |
|
InstrumentScriptVM* m_vm = (InstrumentScriptVM*) vm; |
801 |
|
|
802 |
|
// this might be set by passing 1 with the 2nd argument of built-in stop_wait() function |
803 |
|
if (m_vm->m_event->ignoreAllWaitCalls) return successResult(); |
804 |
|
|
805 |
|
return CoreVMFunction_wait::exec(args); |
806 |
|
} |
807 |
|
|
808 |
|
// stop_wait() function |
809 |
|
|
810 |
|
InstrumentScriptVMFunction_stop_wait::InstrumentScriptVMFunction_stop_wait(InstrumentScriptVM* parent) |
811 |
|
: m_vm(parent) |
812 |
|
{ |
813 |
|
} |
814 |
|
|
815 |
|
VMFnResult* InstrumentScriptVMFunction_stop_wait::exec(VMFnArgs* args) { |
816 |
|
AbstractEngineChannel* pEngineChannel = |
817 |
|
static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
818 |
|
|
819 |
|
const script_callback_id_t id = args->arg(0)->asInt()->evalInt(); |
820 |
|
if (!id) { |
821 |
|
wrnMsg("stop_wait(): callback ID for argument 1 may not be zero"); |
822 |
|
return successResult(); |
823 |
|
} |
824 |
|
|
825 |
|
RTList<ScriptEvent>::Iterator itCallback = pEngineChannel->ScriptCallbackByID(id); |
826 |
|
if (!itCallback) return successResult(); // ignore if callback is i.e. not alive anymore |
827 |
|
|
828 |
|
const bool disableWaitForever = |
829 |
|
(args->argsCount() >= 2) ? (args->arg(1)->asInt()->evalInt() == 1) : false; |
830 |
|
|
831 |
|
pEngineChannel->ScheduleResumeOfScriptCallback( |
832 |
|
itCallback, m_vm->m_event->cause.SchedTime(), disableWaitForever |
833 |
|
); |
834 |
|
|
835 |
|
return successResult(); |
836 |
|
} |
837 |
|
|
838 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |