What's new

Sample Drag drop issues

Hi there, I copied the following part from the example drag and drop script from kontakt. But I can't manage to change the root note to key 84 C4 and I also can't change the Low and High values so the tones can only be played from 60-96

on init

make_perfview
set_ui_height_px(400)
set_ui_width_px(200)
declare $mouse_resp := -900
set_control_par_str($INST_WALLPAPER_ID,$CONTROL_PAR_PICTURE,"I")

declare $i
declare $a
declare $touchedControl
declare @samplePath
declare ~mirPitchResult
declare $play_pos
declare $sampleLength

declare !note[12]
!note[0] := "C"
!note[1] := "C#"
!note[2] := "D"
!note[3] := "D#"
!note[4] := "E"
!note[5] := "F"
!note[6] := "F#"
!note[7] := "G"
!note[8] := "G#"
!note[9] := "A"
!note[10] := "Bb"
!note[11] := "B"
declare !noteName [128]
declare !settingLabelText[3]
!settingLabelText[0] := "Low: "
!settingLabelText[1] := "High: "
!settingLabelText[2] := "Root: "
declare $lowValue
declare $highValue
declare $rootValue
declare $rootMode

$i := 0
while ($i < 128)
!noteName[$i] := !note[$i mod 12] & (($i / 12) - 2)

inc($i)
end while

set_num_user_zones(1)
set_zone_par(%NI_USER_ZONE_IDS[0], $ZONE_PAR_HIGH_VELO, 128)

declare $zone_ID1
$zone_ID1 := %NI_USER_ZONE_IDS[0]
$sampleLength := get_sample_length(%NI_USER_ZONE_IDS[0])
make_persistent($sampleLength)

declare ui_panel $singleDropPanel
when I change these ↓↓↓ nothing happens
$highValue := 127
$rootValue := 72
$lowValue := 0

move_control_px($singleDropPanel, 0, 0)

make_persistent($rootMode)
make_persistent($lowValue)
make_persistent($highValue)
make_persistent($rootValue)
make_persistent(@samplePath)

declare ui_panel $waveArea
declare ui_mouse_area $dropArea
declare ui_waveform $waveView (2, 2)

set_control_par(get_ui_id($dropArea), $CONTROL_PAR_DND_ACCEPT_AUDIO, $NI_DND_ACCEPT_ONE)
set_control_par(get_ui_id($waveArea), $CONTROL_PAR_PARENT_PANEL, get_ui_id($singleDropPanel))

attach_zone($waveView, %NI_USER_ZONE_IDS[0], 0)

declare %areaID[2]
%areaID[0] := get_ui_id($dropArea)
%areaID[1] := get_ui_id($waveView)

$i := 0
while ($i < num_elements(%areaID))
set_control_par(%areaID[$i], $CONTROL_PAR_PARENT_PANEL, get_ui_id($waveArea))
set_control_par(%areaID[$i],$CONTROL_PAR_HIDE,$HIDE_PART_BG)
set_control_par(%areaID[$i], $CONTROL_PAR_WIDTH, 100)
set_control_par(%areaID[$i], $CONTROL_PAR_HEIGHT, 65)
set_control_par(%areaID[$i], $CONTROL_PAR_BG_ALPHA, 0)
set_control_par(%areaID[$i], $CONTROL_PAR_WF_VIS_MODE,$NI_WF_VIS_MODE_3)
inc($i)
end while

declare %settingID[13]
declare %settingID2[13]

declare ui_button $clearSample
declare $clearsampleId
$clearsampleId := get_ui_id($clearsample)
set_control_par_str($clearsampleId, $CONTROL_PAR_PICTURE, "")
set_control_par($clearsampleId, $CONTROL_PAR_WIDTH,40)
set_control_par($clearsampleId, $CONTROL_PAR_HEIGHT,17)
set_control_par($clearsampleId, $CONTROL_PAR_TEXTPOS_Y, 2000)

move_control_px($clearSample, 460, 35)
move_control_px($waveArea, 403, 45)

end on

function setZoneParams()
wait_async(set_zone_par(%NI_USER_ZONE_IDS[0], $ZONE_PAR_LOW_KEY, $lowValue))
wait_async(set_zone_par(%NI_USER_ZONE_IDS[0], $ZONE_PAR_HIGH_KEY, $highValue))
end function

function setLowHigh()
if ($lowValue > $highValue)
$lowValue := $highValue
end if
end function

function setClearSample()
wait_async(set_sample(%NI_USER_ZONE_IDS[0], ""))
end function

on persistence_changed
call setZoneParams()
$touchedControl := 0
while ($touchedControl < 4)
inc($touchedControl)
end while
end on

on ui_control ($dropArea)
if ($NI_MOUSE_EVENT_TYPE = $NI_MOUSE_EVENT_TYPE_DROP)
@samplePath := !NI_DND_ITEMS_AUDIO[0]

wait_async(set_sample(%NI_USER_ZONE_IDS[0], @samplePath))

call setZoneParams()
end if
end on

on ui_control ($clearSample)
if ($clearSample = 1)
call setClearSample()
end if
wait(100000)
$clearSample := 0
end on
 
This factory script comes with two root modes: a) Automatic: the script detects the pitch of the provided sample, and b) Manual: the end-user sets the pitch of the provided sample.

Additionally, there's a function (setZoneParams) that sets the proper root note depending on the root mode selected. This function sets a) the key range and b) the root note. The code you provided includes only the first part (key range).

Factory scripts serve as an excellent resource for studying various concepts in Kontakt.

Check the function setZoneParams. The answer is there :)
 
Ok I got it 🙏🏼
Is there a way to change the color of the sample waveform or is there no other option than white?
 
Top Bottom