/[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 2952 by schoenebeck, Fri Jul 15 15:29:04 2016 UTC revision 2953 by schoenebeck, Sat Jul 16 11:24:39 2016 UTC
# Line 607  namespace LinuxSampler { Line 607  namespace LinuxSampler {
607      }      }
608    
609      #define VM_FILTER_PAR_MAX_VALUE 1000000      #define VM_FILTER_PAR_MAX_VALUE 1000000
610        #define VM_EG_PAR_MAX_VALUE 1000000
611    
612      // change_cutoff() function      // change_cutoff() function
613    
# Line 758  namespace LinuxSampler { Line 759  namespace LinuxSampler {
759                  e.Param.NoteSynthParam.Relative = false;                  e.Param.NoteSynthParam.Relative = false;
760    
761                  pEngineChannel->ScheduleEventMicroSec(&e, 0);                  pEngineChannel->ScheduleEventMicroSec(&e, 0);
762                }
763            }
764    
765            return successResult();
766        }
767        
768        // change_attack() function
769    
770        InstrumentScriptVMFunction_change_attack::InstrumentScriptVMFunction_change_attack(InstrumentScriptVM* parent)
771            : m_vm(parent)
772        {
773        }
774    
775        bool InstrumentScriptVMFunction_change_attack::acceptsArgType(int iArg, ExprType_t type) const {
776            if (iArg == 0)
777                return type == INT_EXPR || type == INT_ARR_EXPR;
778            else
779                return INT_EXPR;
780        }
781    
782        VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {
783            int attack = args->arg(1)->asInt()->evalInt();
784            if (attack > VM_EG_PAR_MAX_VALUE) {
785                wrnMsg("change_attack(): argument 2 may not be larger than 1000000");
786                attack = VM_EG_PAR_MAX_VALUE;
787            } else if (attack < 0) {
788                wrnMsg("change_attack(): argument 2 may not be negative");
789                attack = 0;
790            }
791            const float fAttack = float(attack) / float(VM_EG_PAR_MAX_VALUE);
792    
793            AbstractEngineChannel* pEngineChannel =
794                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
795    
796            if (args->arg(0)->exprType() == INT_EXPR) {
797                const ScriptID id = args->arg(0)->asInt()->evalInt();
798                if (!id) {
799                    wrnMsg("change_attack(): note ID for argument 1 may not be zero");
800                    return successResult();
801                }
802                if (!id.isNoteID()) {
803                    wrnMsg("change_attack(): argument 1 is not a note ID");
804                    return successResult();
805                }
806    
807                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
808                if (!pNote) return successResult();            
809    
810                Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
811                e.Init(); // clear IDs
812                e.Type = Event::type_note_synth_param;
813                e.Param.NoteSynthParam.NoteID   = id.noteID();
814                e.Param.NoteSynthParam.Type     = Event::synth_param_attack;
815                e.Param.NoteSynthParam.Delta    = fAttack;
816                e.Param.NoteSynthParam.Relative = false;
817    
818                pEngineChannel->ScheduleEventMicroSec(&e, 0);
819            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
820                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
821                for (int i = 0; i < ids->arraySize(); ++i) {
822                    const ScriptID id = ids->evalIntElement(i);
823                    if (!id || !id.isNoteID()) continue;
824    
825                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
826                    if (!pNote) continue;
827    
828                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
829                    e.Init(); // clear IDs
830                    e.Type = Event::type_note_synth_param;
831                    e.Param.NoteSynthParam.NoteID   = id.noteID();
832                    e.Param.NoteSynthParam.Type     = Event::synth_param_attack;
833                    e.Param.NoteSynthParam.Delta    = fAttack;
834                    e.Param.NoteSynthParam.Relative = false;
835    
836                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
837                }
838            }
839    
840            return successResult();
841        }
842    
843        // change_decay() function
844        
845        InstrumentScriptVMFunction_change_decay::InstrumentScriptVMFunction_change_decay(InstrumentScriptVM* parent)
846            : m_vm(parent)
847        {
848        }
849    
850        bool InstrumentScriptVMFunction_change_decay::acceptsArgType(int iArg, ExprType_t type) const {
851            if (iArg == 0)
852                return type == INT_EXPR || type == INT_ARR_EXPR;
853            else
854                return INT_EXPR;
855        }
856    
857        VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {
858            int decay = args->arg(1)->asInt()->evalInt();
859            if (decay > VM_EG_PAR_MAX_VALUE) {
860                wrnMsg("change_decay(): argument 2 may not be larger than 1000000");
861                decay = VM_EG_PAR_MAX_VALUE;
862            } else if (decay < 0) {
863                wrnMsg("change_decay(): argument 2 may not be negative");
864                decay = 0;
865            }
866            const float fDecay = float(decay) / float(VM_EG_PAR_MAX_VALUE);
867    
868            AbstractEngineChannel* pEngineChannel =
869                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
870    
871            if (args->arg(0)->exprType() == INT_EXPR) {
872                const ScriptID id = args->arg(0)->asInt()->evalInt();
873                if (!id) {
874                    wrnMsg("change_decay(): note ID for argument 1 may not be zero");
875                    return successResult();
876                }
877                if (!id.isNoteID()) {
878                    wrnMsg("change_decay(): argument 1 is not a note ID");
879                    return successResult();
880                }
881    
882                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
883                if (!pNote) return successResult();            
884    
885                Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
886                e.Init(); // clear IDs
887                e.Type = Event::type_note_synth_param;
888                e.Param.NoteSynthParam.NoteID   = id.noteID();
889                e.Param.NoteSynthParam.Type     = Event::synth_param_decay;
890                e.Param.NoteSynthParam.Delta    = fDecay;
891                e.Param.NoteSynthParam.Relative = false;
892    
893                pEngineChannel->ScheduleEventMicroSec(&e, 0);
894            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
895                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
896                for (int i = 0; i < ids->arraySize(); ++i) {
897                    const ScriptID id = ids->evalIntElement(i);
898                    if (!id || !id.isNoteID()) continue;
899    
900                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
901                    if (!pNote) continue;
902    
903                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
904                    e.Init(); // clear IDs
905                    e.Type = Event::type_note_synth_param;
906                    e.Param.NoteSynthParam.NoteID   = id.noteID();
907                    e.Param.NoteSynthParam.Type     = Event::synth_param_decay;
908                    e.Param.NoteSynthParam.Delta    = fDecay;
909                    e.Param.NoteSynthParam.Relative = false;
910    
911                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
912                }
913            }
914    
915            return successResult();
916        }
917    
918        // change_release() function
919        
920        InstrumentScriptVMFunction_change_release::InstrumentScriptVMFunction_change_release(InstrumentScriptVM* parent)
921            : m_vm(parent)
922        {
923        }
924    
925        bool InstrumentScriptVMFunction_change_release::acceptsArgType(int iArg, ExprType_t type) const {
926            if (iArg == 0)
927                return type == INT_EXPR || type == INT_ARR_EXPR;
928            else
929                return INT_EXPR;
930        }
931    
932        VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {
933            int release = args->arg(1)->asInt()->evalInt();
934            if (release > VM_EG_PAR_MAX_VALUE) {
935                wrnMsg("change_release(): argument 2 may not be larger than 1000000");
936                release = VM_EG_PAR_MAX_VALUE;
937            } else if (release < 0) {
938                wrnMsg("change_release(): argument 2 may not be negative");
939                release = 0;
940            }
941            const float fRelease = float(release) / float(VM_EG_PAR_MAX_VALUE);
942    
943            AbstractEngineChannel* pEngineChannel =
944                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
945    
946            if (args->arg(0)->exprType() == INT_EXPR) {
947                const ScriptID id = args->arg(0)->asInt()->evalInt();
948                if (!id) {
949                    wrnMsg("change_release(): note ID for argument 1 may not be zero");
950                    return successResult();
951                }
952                if (!id.isNoteID()) {
953                    wrnMsg("change_release(): argument 1 is not a note ID");
954                    return successResult();
955                }
956    
957                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
958                if (!pNote) return successResult();            
959    
960                Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
961                e.Init(); // clear IDs
962                e.Type = Event::type_note_synth_param;
963                e.Param.NoteSynthParam.NoteID   = id.noteID();
964                e.Param.NoteSynthParam.Type     = Event::synth_param_release;
965                e.Param.NoteSynthParam.Delta    = fRelease;
966                e.Param.NoteSynthParam.Relative = false;
967    
968                pEngineChannel->ScheduleEventMicroSec(&e, 0);
969            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
970                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
971                for (int i = 0; i < ids->arraySize(); ++i) {
972                    const ScriptID id = ids->evalIntElement(i);
973                    if (!id || !id.isNoteID()) continue;
974    
975                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
976                    if (!pNote) continue;
977    
978                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
979                    e.Init(); // clear IDs
980                    e.Type = Event::type_note_synth_param;
981                    e.Param.NoteSynthParam.NoteID   = id.noteID();
982                    e.Param.NoteSynthParam.Type     = Event::synth_param_release;
983                    e.Param.NoteSynthParam.Delta    = fRelease;
984                    e.Param.NoteSynthParam.Relative = false;
985    
986                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
987              }              }
988          }          }
989    

Legend:
Removed from v.2952  
changed lines
  Added in v.2953

  ViewVC Help
Powered by ViewVC