# Making a Drum Pad Script - Help Needed I hit a Snag see my script....



## K5Addict2107 (Nov 29, 2016)

Hey Guys !! Sorry for being such a noob and i have spent time with the ksp reference manual in addition to the developers script. Trial and error and nights of headaches lol. I am making a drum pad script please excuse the crudity of it , it is 16 drum pads that trigger notes. I have used ui sliders for this in hope to right and midi learn these pads so the point is to use your midi controller to midi learn these pads and the GUI will follow by triggering the pads. This makes a nice visual experience for a user. The script works however the GUI pads will not midi lean :/ super aggravating to say the least what am i doing wrong ?? i could add 1 pad here cause of the 1000 character limit sorry i have the full script if you need it but here is the script ..

on init
set_script_title("drum test - Kontakt Addict2017")
set_ui_height_px(225)
make_perfview

declare %pad[16] 
declare $count 
declare ui_switch $drum_pad2
declare %pad_id[16] 
%pad_id[1] := get_ui_id($drum_pad2)
$count := 0
while ($count < 16)
set_control_par(%pad_id[$count], $CONTROL_PAR_HEIGHT,75)
set_control_par(%pad_id[$count], $CONTROL_PAR_WIDTH,75)
set_control_par_str(%pad_id[$count], $CONTROL_PAR_PICTURE, "later")
$count := 0
while ($count < 16)
set_control_par(%pad_id[$count], $CONTROL_PAR_HEIGHT,75)
set_control_par(%pad_id[$count], $CONTROL_PAR_WIDTH,75)
set_control_par_str(%pad_id[$count], $CONTROL_PAR_PICTURE, " later2")
inc ($count)
end while 
inc ($count)
move_control_px($drum_pad2, 20, 70)
make_persistent ($drum_pad2)
read_persistent_var ($drum_pad2)
end while
end on
on ui_control ($drum_pad2) 
if ($drum_pad2=1)
else
$drum_pad2 := 1
$drum_pad2 := 1
play_note(48,100,0,0)
%pad[1] := $drum_pad2
end if
end on


----------



## d.healey (Nov 30, 2016)

This code is very odd, you are resetting count to 0 everytime you go through the loop... if you want 2 loops you should use 2 counters.


```
$count := 0   
    while ($count < 16)
       
        set_control_par(%pad_id[$count], $CONTROL_PAR_HEIGHT,75)
        set_control_par(%pad_id[$count], $CONTROL_PAR_WIDTH,75)
        set_control_par_str(%pad_id[$count], $CONTROL_PAR_PICTURE, "later")
       
        $count := 0
        while ($count < 16)
            set_control_par(%pad_id[$count], $CONTROL_PAR_HEIGHT,75)
            set_control_par(%pad_id[$count], $CONTROL_PAR_WIDTH,75)
            set_control_par_str(%pad_id[$count], $CONTROL_PAR_PICTURE, " later2")
            inc ($count)
        end while
   
        inc ($count)
        move_control_px($drum_pad2, 20, 70)
        make_persistent ($drum_pad2)
        read_persistent_var ($drum_pad2)

    end while
```


----------



## K5Addict2107 (Nov 30, 2016)

ok thanks i really appreciate this help. So how can i make it right click to midi learn to the midi controller. It strikes me odd as i am using a slider that should be able to map. i think my code has en error in somewhere


----------



## d.healey (Nov 30, 2016)

I'm not sure what you mean by MIDI learn in this context, you script isn't responding to any MIDI inputs


----------



## K5Addict2107 (Nov 30, 2016)

d.healey said:


> I'm not sure what you mean by MIDI learn in this context, you script isn't responding to any MIDI inputs



Oks thats the error how would i set that up the script ?? any help would be greatly appreciated. Like can you show me an example with the script i provided so that the 1 pad will respond to the midi input. After that im sure i can figured out the rest ??


----------



## d.healey (Nov 30, 2016)

Look up callbacks in the user guide. For MIDI input it's the on note and on controller callbacks you'll mainly be interested in. If you just want the built in MIDI learn feature then you just need to right-click on the slider and select the MIDI learn option


----------



## K5Addict2107 (Dec 1, 2016)

d.healey said:


> Look up callbacks in the user guide. For MIDI input it's the on note and on controller callbacks you'll mainly be interested in. If you just want the built in MIDI learn feature then you just need to right-click on the slider and select the MIDI learn option


Ok thanks well i looked up the call backs I added them to the script however same result - I right on the pad - its midi learn as it should - tap on the midi controller and it still not map :/ I think I need your expertise on this one. The Drum pad triggers a sample fine on C2 as it should as well. I'm not worried about any loops , I just want to Right click and midi Learn to the Midi controller. Can you show me the correct way with the script provided above ??


----------



## EvilDragon (Dec 2, 2016)

Right-click MIDI learn is handled entirely by Kontakt, scripting cannot influence it in any way.


----------



## geronimo (Dec 2, 2016)

Moreover, if one searches with the word "midilearn" in the KSP manual, one finds nothing.


----------



## EvilDragon (Dec 2, 2016)

That's because it's not one word. 

Also, see section 3.8.


----------



## K5Addict2107 (Dec 2, 2016)

EvilDragon said:


> That's because it's not one word.
> 
> Also, see section 3.8.


Hey guys thanks for the reply. Maybe im not making myself clear my fault. the problem is not midi learn. I will upload this script so you can see the problem im having. Add a sound on C2. The midi learn work however when it is clicked and i tap on a key on the midi control the pad sound will not map to the hardware midi controller. As explained by healy he states i must have not scripted the inputs and outputs for the midi correct ?? i looked in the manual and i added the on controller but still i get the same result. Maybe someone can download the attached file and give me an example to make it work


----------



## EvilDragon (Dec 2, 2016)

MIDI learn works only for MIDI CCs. Not MIDI notes.


----------



## K5Addict2107 (Dec 2, 2016)

Thanks Evil Dragon your help is Golden !


----------



## K5Addict2107 (Dec 2, 2016)

Hey Evil Dragon i have one last question about the drum pad script. Lets say i did a declare ui_waveform for a visual feel to it and the wav file appears. How would i tap on the GUI pad and make the wav display change for each attach_zone($my_waveform,find_zone("Zone"),$UI_WAVEFORM_TABLE_IS_BIPOLAR) in the script ??


----------



## K5Addict2107 (Dec 2, 2016)

See the updated zip below the wav form plays however when i push the pad with the mouse the display will not trigger why is this ??? im getting grey hairs on this :roll:


----------



## EvilDragon (Dec 2, 2016)

You need to attach_zone() in the button's UI callback, as well, but first you need to get the zone ID from the event you played with play_note() in that callback.


----------



## K5Addict2107 (Dec 6, 2016)

EvilDragon said:


> You need to attach_zone() in the button's UI callback, as well, but first you need to get the zone ID from the event you played with play_note() in that callback.


I hate to be a bug-a-boo but can you give me an example with the script zip i have above. it would be greatly appreciated.


----------

