/[svn]/linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2931 by schoenebeck, Sat Jul 9 14:38:33 2016 UTC revision 2935 by schoenebeck, Sun Jul 10 14:24:13 2016 UTC
# Line 601  namespace LinuxSampler { Line 601  namespace LinuxSampler {
601          return successResult();          return successResult();
602      }      }
603    
604        #define VM_FILTER_PAR_MAX_VALUE 1000000
605    
606        // change_cutoff() function
607    
608        InstrumentScriptVMFunction_change_cutoff::InstrumentScriptVMFunction_change_cutoff(InstrumentScriptVM* parent)
609            : m_vm(parent)
610        {
611        }
612    
613        bool InstrumentScriptVMFunction_change_cutoff::acceptsArgType(int iArg, ExprType_t type) const {
614            if (iArg == 0)
615                return type == INT_EXPR || type == INT_ARR_EXPR;
616            else
617                return INT_EXPR;
618        }
619    
620        VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) {
621            int cutoff = args->arg(1)->asInt()->evalInt();
622            if (cutoff > VM_FILTER_PAR_MAX_VALUE) {
623                wrnMsg("change_cutoff(): argument 2 may not be larger than 1000000");
624                cutoff = VM_FILTER_PAR_MAX_VALUE;
625            } else if (cutoff < 0) {
626                wrnMsg("change_cutoff(): argument 2 may not be negative");
627                cutoff = 0;
628            }
629    
630            AbstractEngineChannel* pEngineChannel =
631                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
632    
633            if (args->arg(0)->exprType() == INT_EXPR) {
634                const ScriptID id = args->arg(0)->asInt()->evalInt();
635                if (!id) {
636                    wrnMsg("change_cutoff(): note ID for argument 1 may not be zero");
637                    return successResult();
638                }
639                if (!id.isNoteID()) {
640                    wrnMsg("change_cutoff(): argument 1 is not a note ID");
641                    return successResult();
642                }
643    
644                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
645                if (!pNote) return successResult();
646    
647                const float fCutoff = float(cutoff) / float(VM_FILTER_PAR_MAX_VALUE);
648    
649                Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
650                e.Init(); // clear IDs
651                e.Type = Event::type_note_synth_param;
652                e.Param.NoteSynthParam.NoteID   = id.noteID();
653                e.Param.NoteSynthParam.Type     = Event::synth_param_cutoff;
654                e.Param.NoteSynthParam.Delta    = fCutoff;
655                e.Param.NoteSynthParam.Relative = false;
656    
657                pEngineChannel->ScheduleEventMicroSec(&e, 0);
658            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
659                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
660                for (int i = 0; i < ids->arraySize(); ++i) {
661                    const ScriptID id = ids->evalIntElement(i);
662                    if (!id || !id.isNoteID()) continue;
663    
664                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
665                    if (!pNote) continue;
666    
667                    const float fCutoff = float(cutoff) / float(VM_FILTER_PAR_MAX_VALUE);
668    
669                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
670                    e.Init(); // clear IDs
671                    e.Type = Event::type_note_synth_param;
672                    e.Param.NoteSynthParam.NoteID   = id.noteID();
673                    e.Param.NoteSynthParam.Type     = Event::synth_param_cutoff;
674                    e.Param.NoteSynthParam.Delta    = fCutoff;
675                    e.Param.NoteSynthParam.Relative = false;
676    
677                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
678                }
679            }
680    
681            return successResult();
682        }
683    
684        // change_reso() function
685        
686        InstrumentScriptVMFunction_change_reso::InstrumentScriptVMFunction_change_reso(InstrumentScriptVM* parent)
687            : m_vm(parent)
688        {
689        }
690    
691        bool InstrumentScriptVMFunction_change_reso::acceptsArgType(int iArg, ExprType_t type) const {
692            if (iArg == 0)
693                return type == INT_EXPR || type == INT_ARR_EXPR;
694            else
695                return INT_EXPR;
696        }
697    
698        VMFnResult* InstrumentScriptVMFunction_change_reso::exec(VMFnArgs* args) {
699            int resonance = args->arg(1)->asInt()->evalInt();
700            if (resonance > VM_FILTER_PAR_MAX_VALUE) {
701                wrnMsg("change_reso(): argument 2 may not be larger than 1000000");
702                resonance = VM_FILTER_PAR_MAX_VALUE;
703            } else if (resonance < 0) {
704                wrnMsg("change_reso(): argument 2 may not be negative");
705                resonance = 0;
706            }
707    
708            AbstractEngineChannel* pEngineChannel =
709                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
710    
711            if (args->arg(0)->exprType() == INT_EXPR) {
712                const ScriptID id = args->arg(0)->asInt()->evalInt();
713                if (!id) {
714                    wrnMsg("change_reso(): note ID for argument 1 may not be zero");
715                    return successResult();
716                }
717                if (!id.isNoteID()) {
718                    wrnMsg("change_reso(): argument 1 is not a note ID");
719                    return successResult();
720                }
721    
722                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
723                if (!pNote) return successResult();
724    
725                const float fResonance = float(resonance) / float(VM_FILTER_PAR_MAX_VALUE);
726    
727                Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
728                e.Init(); // clear IDs
729                e.Type = Event::type_note_synth_param;
730                e.Param.NoteSynthParam.NoteID   = id.noteID();
731                e.Param.NoteSynthParam.Type     = Event::synth_param_resonance;
732                e.Param.NoteSynthParam.Delta    = fResonance;
733                e.Param.NoteSynthParam.Relative = false;
734    
735                pEngineChannel->ScheduleEventMicroSec(&e, 0);
736            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
737                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
738                for (int i = 0; i < ids->arraySize(); ++i) {
739                    const ScriptID id = ids->evalIntElement(i);
740                    if (!id || !id.isNoteID()) continue;
741    
742                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
743                    if (!pNote) continue;
744    
745                    const float fResonance = float(resonance) / float(VM_FILTER_PAR_MAX_VALUE);
746    
747                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
748                    e.Init(); // clear IDs
749                    e.Type = Event::type_note_synth_param;
750                    e.Param.NoteSynthParam.NoteID   = id.noteID();
751                    e.Param.NoteSynthParam.Type     = Event::synth_param_resonance;
752                    e.Param.NoteSynthParam.Delta    = fResonance;
753                    e.Param.NoteSynthParam.Relative = false;
754    
755                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
756                }
757            }
758    
759            return successResult();
760        }
761    
762        // event_status() function
763    
764        InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)
765            : m_vm(parent)
766        {
767        }
768    
769        VMFnResult* InstrumentScriptVMFunction_event_status::exec(VMFnArgs* args) {
770            AbstractEngineChannel* pEngineChannel =
771                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
772    
773            const ScriptID id = args->arg(0)->asInt()->evalInt();
774            if (!id) {
775                wrnMsg("event_status(): note ID for argument 1 may not be zero");
776                return successResult(EVENT_STATUS_INACTIVE);
777            }
778            if (!id.isNoteID()) {
779                wrnMsg("event_status(): argument 1 is not a note ID");
780                return successResult(EVENT_STATUS_INACTIVE);
781            }
782    
783            NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
784            return successResult(pNote ? EVENT_STATUS_NOTE_QUEUE : EVENT_STATUS_INACTIVE);
785        }
786    
787  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2931  
changed lines
  Added in v.2935

  ViewVC Help
Powered by ViewVC