on init
  declare ui_value_edit $tuning(-100000, 100000, 1000)  { amount of detuning }
  declare ui_button $tuning_active                      { detuning on/off }
end on

on note
  if ($tuning_active = 1)                    { if the button is in it's pressed state then ... }
    change_tune($EVENT_ID, $tuning, 0)       { change tuning by user-specified amount          }
  end if
end on

on init
  declare %notes[8] := (0, 4, 7, 4, 12, 4, 7, 4)
  declare $i
end on

on note
  ignore_event($EVENT_ID)         
  $i := 0                         { assign the value 0 to $i }  
  while ($i < 8)                  { repeat while $i is less than 8 }
    play_note($EVENT_NOTE + %notes[$i], $EVENT_VELOCITY, 0, 100000)
    wait(100000)   
    inc($i)                       { increment $i by one }  
  end while
end on

function mytest(a, b)
  message(a & b)
end function

macro add_mod_par(#prop#,engine_par)
    property group.mods.#prop#
        function get(group,mods) -> result
            result := get_engine_par(engine_par,group,find_mod(group,mods),-1)
        end function
        
        function set(group,mods,value)
            set_engine_par(engine_par,value,group,find_mod(group,mods),-1)
        end function
    end property

    property group.mods.#prop#.disp
        function get(group,mods) -> result
            result := get_engine_par_disp(engine_par,group,find_mod(group,mods),-1)
        end function
    end property
    
    sdfmodsdf

    property group.mods.target.#prop#
        function get(group,mods,target) -> result
            result := get_engine_par(engine_par,group,find_mod(group,mods),find_target(group,find_mod(group,mods),target))
        end function
        
        function set(group,mods,target,value)
            set_engine_par(engine_par,value,group,find_mod(group,mods),find_target(group,find_mod(group,mods),target))
        end function
    end property
    
    property group.mods.target.#prop#.disp
        function get(group,mods,target) -> result
            result := get_engine_par_disp(engine_par,group,find_mod(group,mods),find_target(group,find_mod(group,mods),target))
        end function
    end property
end macro

macro add_engine_par(#prop#,engine_par)
    property insert.#prop#
        function get(slot) -> result
            result := get_engine_par(engine_par,-1,slot,1)
        end function

        function set(slot, value)
            set_engine_par(engine_par,value,-1,slot,1)
        end function    
    end property

    property insert.#prop#.disp
        function get(slot) -> result
            result := get_engine_par_disp(engine_par,-1,slot,1)
        end function
    end property

    property send.#prop#
        function get(slot) -> result
            result := get_engine_par(engine_par,-1,slot,0)
        end function

        function set(slot,value)
            set_engine_par(engine_par,value,-1,slot,0)
        end function
    end property

    property send.#prop#.disp
        function get(slot) -> result
            result := get_engine_par_disp(engine_par,-1,slot,0)
        end function
    end property

    property group.slot.#prop#
        function get(group,slot) -> result
            result := get_engine_par(engine_par,group,slot,-1)
        end function

        function set(group,slot,value)
            set_engine_par(engine_par,value,group,slot,-1)
        end function
    end property

    property group.slot.#prop#.disp
        function get(group,slot) -> result
            result := get_engine_par_disp(engine_par,group,slot,-1)
        end function
    end property

    property bus.slot.#prop#
        function get(bus,slot) -> result
            result := get_engine_par(engine_par,-1,slot,NI_BUS_OFFSET + bus)
        end function

        function set(bus,slot,value)
            set_engine_par(engine_par,value,-1,slot,NI_BUS_OFFSET + bus)
        end function
    end property

    property bus.slot.#prop#.disp
        function get(bus,slot) -> result
            result := get_engine_par_disp(engine_par,-1,slot,NI_BUS_OFFSET + bus)
        end function
    end property
end macro

function init_parameters()
    { Instrument, Source, Amp }
    add_engine_par(volume,        ENGINE_PAR_VOLUME)
    add_engine_par(pan,           ENGINE_PAR_PAN)
    add_engine_par(tune,          ENGINE_PAR_TUNE)
    add_engine_par(speed,         ENGINE_PAR_SPEED)
    add_engine_par(tm_smooth,     ENGINE_PAR_SMOOTH)
    add_engine_par(tm_formant,    ENGINE_PAR_FORMANT)
    add_engine_par(tm_grain,      ENGINE_PAR_GRAIN_LENGTH)
    add_engine_par(tm2_trans,     ENGINE_PAR_TRANSIENT_SIZE)
    add_engine_par(tmp_envorder,  ENGINE_PAR_ENVELOPE_ORDER)
    add_engine_par(tmp_formant,   ENGINE_PAR_FORMANT_SHIFT)
    add_engine_par(bm_slice_atk,  ENGINE_PAR_SLICE_ATTACK)
    add_engine_par(bm_slice_rel,  ENGINE_PAR_SLICE_RELEASE)
    add_engine_par(out_chan,      ENGINE_PAR_OUTPUT_CHANNEL)
    { GET only! }
    add_engine_par(rel_trig,      ENGINE_PAR_RELEASE_TRIGGER)
    
    { Insert FX }
    add_engine_par(ifx_bypass,    ENGINE_PAR_EFFECT_BYPASS)
    add_engine_par(ifx_outgain,   ENGINE_PAR_INSERT_EFFECT_OUTPUT_GAIN)
    
    { Send FX }
    add_engine_par(sfx_bypass,    ENGINE_PAR_SEND_EFFECT_BYPASS)
    add_engine_par(sfx_dry,       ENGINE_PAR_SEND_EFFECT_DRY_LEVEL)
    add_engine_par(sfx_outgain,   ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN)
    
    { Filters }
    add_engine_par(filt_cutoff,   ENGINE_PAR_CUTOFF)
    add_engine_par(filt_shift2,   ENGINE_PAR_FILTER_SHIFTB)
    add_engine_par(filt_shift3,   ENGINE_PAR_FILTER_SHIFTC)
    add_engine_par(filt_res,      ENGINE_PAR_RESONANCE)
    add_engine_par(filt_res2,     ENGINE_PAR_FILTER_RESB)
    add_engine_par(filt_res3,     ENGINE_PAR_FILTER_RESC)
    add_engine_par(filt_type1,    ENGINE_PAR_FILTER_TYPEA)
    add_engine_par(filt_type2,    ENGINE_PAR_FILTER_TYPEB)
    add_engine_par(filt_type3,    ENGINE_PAR_FILTER_TYPEC)
    add_engine_par(filt_amt1,     ENGINE_PAR_FILTER_BYPA)
    add_engine_par(filt_amt2,     ENGINE_PAR_FILTER_BYPB)
    add_engine_par(filt_amt3,     ENGINE_PAR_FILTER_BYPC)
    add_engine_par(filt_gain3x2,  ENGINE_PAR_FILTER_GAIN)
    add_engine_par(filt_bw,       ENGINE_PAR_BANDWIDTH)
    add_engine_par(filt_gain,     ENGINE_PAR_GAIN)
    add_engine_par(filt_sharp,    ENGINE_PAR_FORMANT_SHARP)
    add_engine_par(filt_size,     ENGINE_PAR_FORMANT_SIZE)
    add_engine_par(filt_talk,     ENGINE_PAR_FORMANT_TALK)
    { Solid G-EQ }
    add_engine_par(seq_hf_bell,   ENGINE_PAR_SEQ_HF_BELL)
    add_engine_par(seq_hf_freq,   ENGINE_PAR_SEQ_HF_FREQ)
    add_engine_par(seq_hf_gain,   ENGINE_PAR_SEQ_HF_GAIN)
    add_engine_par(seq_hmf_freq,  ENGINE_PAR_SEQ_HMF_FREQ)
    add_engine_par(seq_hmf_gain,  ENGINE_PAR_SEQ_HMF_GAIN)
    add_engine_par(seq_hmf_q,     ENGINE_PAR_SEQ_HMF_Q)
    add_engine_par(seq_lf_bell,   ENGINE_PAR_SEQ_LF_BELL)
    add_engine_par(seq_lf_freq,   ENGINE_PAR_SEQ_LF_FREQ)
    add_engine_par(seq_lf_gain,   ENGINE_PAR_SEQ_LF_GAIN)
    add_engine_par(seq_lmf_freq,  ENGINE_PAR_SEQ_LMF_FREQ)
    add_engine_par(seq_lmf_gain,  ENGINE_PAR_SEQ_LMF_GAIN)
    add_engine_par(seq_lmf_q,     ENGINE_PAR_SEQ_LMF_Q)    
    { Equalizers }
    add_engine_par(eq_freq1,      ENGINE_PAR_FREQ1)
    add_engine_par(eq_freq2,      ENGINE_PAR_FREQ2)
    add_engine_par(eq_freq3,      ENGINE_PAR_FREQ3)
    add_engine_par(eq_bw1,        ENGINE_PAR_BW1)
    add_engine_par(eq_bw2,        ENGINE_PAR_BW2)
    add_engine_par(eq_bw3,        ENGINE_PAR_BW3)
    add_engine_par(eq_gain1,      ENGINE_PAR_GAIN1)
    add_engine_par(eq_gain2,      ENGINE_PAR_GAIN2)
    add_engine_par(eq_gain3,      ENGINE_PAR_GAIN3)
    
    { AET Filter }
    add_engine_par(aet_morph,     ENGINE_PAR_EXP_FILTER_MORPH)
    add_engine_par(aet_amount,    ENGINE_PAR_EXP_FILTER_AMOUNT)
    { Transient Master }
    add_engine_par(tr_input,      ENGINE_PAR_TR_INPUT)
    add_engine_par(tr_atk,        ENGINE_PAR_TR_ATTACK)
    add_engine_par(tr_sus,        ENGINE_PAR_TR_SUSTAIN)
    { Solid Bus Comp }
    add_engine_par(scomp_thres,   ENGINE_PAR_SCOMP_THRESHOLD)
    add_engine_par(scomp_attack,  ENGINE_PAR_SCOMP_ATTACK)
    add_engine_par(scomp_makeup,  ENGINE_PAR_SCOMP_MAKEUP)
    add_engine_par(scomp_ratio,   ENGINE_PAR_SCOMP_RATIO)
    add_engine_par(scomp_rel,     ENGINE_PAR_SCOMP_RELEASE)
    add_engine_par(scomp_mix,     ENGINE_PAR_SCOMP_MIX)
    { Compressor }
    add_engine_par(comp_thres,    ENGINE_PAR_THRESHOLD)
    add_engine_par(comp_ratio,    ENGINE_PAR_RATIO)
    add_engine_par(comp_atk,      ENGINE_PAR_COMP_ATTACK)
    add_engine_par(comp_dec,      ENGINE_PAR_COMP_DECAY)
    { Limiter }
    add_engine_par(lim_input,     ENGINE_PAR_LIM_IN_GAIN)
    add_engine_par(lim_rel,       ENGINE_PAR_LIM_RELEASE)
    { Tape Saturation }
    add_engine_par(tape_gain,     ENGINE_PAR_TP_GAIN)
    add_engine_par(tape_warmth,   ENGINE_PAR_TP_WARMTH)
    add_engine_par(tape_rolloff,  ENGINE_PAR_TP_HF_ROLLOFF)
    { Distortion }
    add_engine_par(dist_drive,    ENGINE_PAR_DRIVE)
    add_engine_par(dist_damp,     ENGINE_PAR_DAMPING)
    { Lo-Fi }
    add_engine_par(lofi_freq,     ENGINE_PAR_FREQUENCY)
    add_engine_par(lofi_bits,     ENGINE_PAR_BITS)
    add_engine_par(lofi_noise,    ENGINE_PAR_NOISELEVEL)
    add_engine_par(lofi_color,    ENGINE_PAR_NOISECOLOR)
    { Saturation }
    add_engine_par(saturation,    ENGINE_PAR_SHAPE)
    { Cabinet }
    add_engine_par(cab_type,      ENGINE_PAR_CABINET_TYPE)
    add_engine_par(cab_size,      ENGINE_PAR_CB_SIZE)
    add_engine_par(cab_air,       ENGINE_PAR_CB_AIR)
    add_engine_par(cab_bass,      ENGINE_PAR_CB_BASS)
    add_engine_par(cab_treble,    ENGINE_PAR_CB_TREBLE)
    { Skreamer }
    add_engine_par(sk_tone,       ENGINE_PAR_SK_TONE)
    add_engine_par(sk_drive,      ENGINE_PAR_SK_DRIVE)
    add_engine_par(sk_bass,       ENGINE_PAR_SK_BASS)
    add_engine_par(sk_bright,     ENGINE_PAR_SK_BRIGHT)
    add_engine_par(sk_clean,      ENGINE_PAR_SK_MIX)
    { Twang }
    add_engine_par(tw_volume,     ENGINE_PAR_TW_VOLUME)
    add_engine_par(tw_treble,     ENGINE_PAR_TW_TREBLE)
    add_engine_par(tw_mid,        ENGINE_PAR_TW_MID)
    add_engine_par(tw_bass,       ENGINE_PAR_TW_BASS)
    { Rotator }
    add_engine_par(rot_speed,     ENGINE_PAR_RT_SPEED)
    add_engine_par(rot_accel_hi,  ENGINE_PAR_RT_ACCEL_HI)
    add_engine_par(rot_accel_lo,  ENGINE_PAR_RT_ACCEL_LO)
    add_engine_par(rot_balance,   ENGINE_PAR_RT_BALANCE)
    add_engine_par(rot_distance,  ENGINE_PAR_RT_DISTANCE)
    add_engine_par(rot_mix,       ENGINE_PAR_RT_MIX)
    { Surround Panner }
    add_engine_par(sp_diverge,    ENGINE_PAR_SP_DIVERGENCE)
    add_engine_par(sp_size,       ENGINE_PAR_SP_SIZE)
    add_engine_par(sp_lfe,        ENGINE_PAR_SP_LFE_VOLUME)
    add_engine_par(sp_xshift,     ENGINE_PAR_SP_OFFSET_X)
    add_engine_par(sp_yshift,     ENGINE_PAR_SP_OFFSET_Y)
    add_engine_par(sp_angle,      ENGINE_PAR_SP_OFFSET_AZIMUTH)
    add_engine_par(sp_distance,   ENGINE_PAR_SP_OFFSET_DISTANCE)
    { Stereo Modeller }
    add_engine_par(stereo_spread, ENGINE_PAR_STEREO)    
    add_engine_par(stereo_pan,    ENGINE_PAR_STEREO_PAN)
    { Delay }
    add_engine_par(dl_time,       ENGINE_PAR_DL_TIME)
    add_engine_par(dl_damp,       ENGINE_PAR_DL_DAMPING)
    add_engine_par(dl_pan,        ENGINE_PAR_DL_PAN)
    add_engine_par(dl_feed,       ENGINE_PAR_DL_FEEDBACK)
    { Chorus }
    add_engine_par(ch_depth,      ENGINE_PAR_CH_DEPTH)
    add_engine_par(ch_speed,      ENGINE_PAR_CH_SPEED)
    add_engine_par(ch_phase,      ENGINE_PAR_CH_PHASE)
    { Flanger }
    add_engine_par(fl_depth,      ENGINE_PAR_FL_DEPTH)
    add_engine_par(fl_speed,      ENGINE_PAR_FL_SPEED)
    add_engine_par(fl_phase,      ENGINE_PAR_FL_PHASE)
    add_engine_par(fl_color,      ENGINE_PAR_FL_COLOR)
    add_engine_par(fl_feed,       ENGINE_PAR_FL_FEEDBACK)
    { Phaser }
    add_engine_par(ph_depth,      ENGINE_PAR_PH_DEPTH)
    add_engine_par(ph_speed,      ENGINE_PAR_PH_SPEED)
    add_engine_par(ph_phase,      ENGINE_PAR_PH_PHASE)
    add_engine_par(ph_feed,       ENGINE_PAR_PH_FEEDBACK)
    { Convolution }
    add_engine_par(ir_predelay,   ENGINE_PAR_IRC_PREDELAY)
    add_engine_par(ir_size_er,    ENGINE_PAR_IRC_LENGTH_RATIO_ER)
    add_engine_par(ir_hp_er,      ENGINE_PAR_IRC_FREQ_HIGHPASS_ER)
    add_engine_par(ir_lp_er,      ENGINE_PAR_IRC_FREQ_LOWPASS_ER)
    add_engine_par(ir_size_lr,    ENGINE_PAR_IRC_LENGTH_RATIO_LR)
    add_engine_par(ir_hp_lr,      ENGINE_PAR_IRC_FREQ_HIGHPASS_LR)
    add_engine_par(ir_lp_lr,      ENGINE_PAR_IRC_FREQ_LOWPASS_LR)
    { Reverb }
    add_engine_par(rev_predelay,  ENGINE_PAR_RV_PREDELAY)
    add_engine_par(rev_size,      ENGINE_PAR_RV_SIZE)
    add_engine_par(rev_color,     ENGINE_PAR_RV_COLOUR)
    add_engine_par(rev_damp,      ENGINE_PAR_RV_DAMPING)
    add_engine_par(rev_stereo,    ENGINE_PAR_RV_STEREO)
    { Gainer }
    add_engine_par(gainer,        ENGINE_PAR_GN_GAIN)
    { Send Levels }
    add_engine_par(send_0,        ENGINE_PAR_SENDLEVEL_0)
    add_engine_par(send_1,        ENGINE_PAR_SENDLEVEL_1)
    add_engine_par(send_2,        ENGINE_PAR_SENDLEVEL_2)
    add_engine_par(send_3,        ENGINE_PAR_SENDLEVEL_3)
    add_engine_par(send_4,        ENGINE_PAR_SENDLEVEL_4)
    add_engine_par(send_5,        ENGINE_PAR_SENDLEVEL_5)
    add_engine_par(send_6,        ENGINE_PAR_SENDLEVEL_6)
    add_engine_par(send_7,        ENGINE_PAR_SENDLEVEL_7)
    add_engine_par(send_smooth_0, ENGINE_PAR_SENDLEVEL_SMOOTHED_0)
    add_engine_par(send_smooth_1, ENGINE_PAR_SENDLEVEL_SMOOTHED_1)
    add_engine_par(send_smooth_2, ENGINE_PAR_SENDLEVEL_SMOOTHED_2)
    add_engine_par(send_smooth_3, ENGINE_PAR_SENDLEVEL_SMOOTHED_3)
    add_engine_par(send_smooth_4, ENGINE_PAR_SENDLEVEL_SMOOTHED_4)
    add_engine_par(send_smooth_5, ENGINE_PAR_SENDLEVEL_SMOOTHED_5)
    add_engine_par(send_smooth_6, ENGINE_PAR_SENDLEVEL_SMOOTHED_6)
    add_engine_par(send_smooth_7, ENGINE_PAR_SENDLEVEL_SMOOTHED_7)

    { Modulation }
    add_mod_par(mod_bypass,       ENGINE_PAR_INTMOD_BYPASS)
    add_mod_par(mod_freq,         ENGINE_PAR_INTMOD_FREQUENCY)
    add_mod_par(mod_amt,          ENGINE_PAR_INTMOD_INTENSITY)
    add_mod_par(mod_amt_uni,      ENGINE_PAR_MOD_TARGET_INTENSITY)
    { Envelopes }
    add_mod_par(env_curve,        ENGINE_PAR_ATK_CURVE)
    add_mod_par(env_atk,          ENGINE_PAR_ATTACK)
    add_mod_par(env_hold,         ENGINE_PAR_HOLD)
    add_mod_par(env_dec,          ENGINE_PAR_DECAY)
    add_mod_par(env_sus,          ENGINE_PAR_SUSTAIN)
    add_mod_par(env_rel,          ENGINE_PAR_RELEASE)
    add_mod_par(env_decay1,       ENGINE_PAR_DECAY1)
    add_mod_par(env_break,        ENGINE_PAR_BREAK)
    add_mod_par(env_decay2,       ENGINE_PAR_DECAY2)
    { LFOs }
    add_mod_par(lfo_delay,        ENGINE_PAR_LFO_DELAY)
    add_mod_par(lfo_sine,         ENGINE_PAR_LFO_SINE)
    add_mod_par(lfo_tri,          ENGINE_PAR_LFO_TRI)
    add_mod_par(lfo_rect,         ENGINE_PAR_LFO_RECT)
    add_mod_par(lfo_saw,          ENGINE_PAR_LFO_SAW)
    add_mod_par(lfo_rand,         ENGINE_PAR_LFO_RAND)
    { Glide }
    add_mod_par(glide_speed,      ENGINE_PAR_GLIDE_COEF)
end function