2 x Waveform Display - Attach Zone Problem

MTC84
MTC84 Member Posts: 71 Member
edited October 2024 in Scripting Workshop

Hi,

Can anyone put me out of my misery please!?

Currently, the Menu's populate with the correct names but the Menu B isn't behaving as it should. If I select a sample from Menu B the wrong sound is played. It is playing the Group linked to Menu A and not the from the groups linked to Menu B.

Also, the incorrect zone is being displayed in Waveform B.

What am I missing here? I guess it is a simple mistake I have made.

Thanks muchly.

on init
make_perfview
declare const $UI_HEIGHT := 220
set_ui_height_px(220) set_skin_offset(0)
message ("")

declare $Menu_A_LAST := 1
declare $Menu_B_LAST := 3



declare $Count_Menu_A
declare $Count_Menu_B

declare $Zone_A
declare $Zone_B

declare $Event_A
declare $Event_B {SAMPLE SELECT MENUS} declare $i
declare $GROUP_COUNT
$GROUP_COUNT := $NUM_GROUPS / 2

declare ui_menu $MENU_A
move_control_px($MENU_A, 216, 106)
set_control_par(get_ui_id($MENU_A), $CONTROL_PAR_WIDTH, 91)


declare ui_menu $MENU_B
move_control_px($MENU_B, 326, 106)
set_control_par(get_ui_id($MENU_B), $CONTROL_PAR_WIDTH, 91)

while ($i < $GROUP_COUNT)
add_menu_item($MENU_A, group_name($i), $i)
add_menu_item($MENU_B, group_name($i + $GROUP_COUNT), $i)
inc($i)
end while


make_persistent($MENU_A)
make_persistent($MENU_B) {WAVEFORM DISPLAY - A + B} declare ui_waveform $Waveform_A (6, 6)
move_control_px($Waveform_A, 5, 79)
set_control_par(get_ui_id($Waveform_A), $CONTROL_PAR_WIDTH, 202)
set_control_par(get_ui_id($Waveform_A), $CONTROL_PAR_HEIGHT, 46)
set_control_par(get_ui_id($Waveform_A), $CONTROL_PAR_BG_ALPHA, 9000000h)
set_control_par(get_ui_id($Waveform_A), $CONTROL_PAR_WAVE_COLOR, 9ffffffh)
hide_part ($Waveform_A, $HIDE_PART_BG)

declare ui_waveform $Waveform_B (6, 6)
move_control_px($Waveform_B, 426, 79)
set_control_par(get_ui_id($Waveform_B), $CONTROL_PAR_WIDTH, 202)
set_control_par(get_ui_id($Waveform_B), $CONTROL_PAR_HEIGHT, 46)
set_control_par(get_ui_id($Waveform_B), $CONTROL_PAR_BG_ALPHA, 9000000h)
set_control_par(get_ui_id($Waveform_B), $CONTROL_PAR_WAVE_COLOR, 9ffffffh)
hide_part ($Waveform_B, $HIDE_PART_BG) end on {FUNCTIONS}
{ATTACH WAVEFORM ZONE A + B} function FUNC_ATTACH_ZONE_A
$Zone_A := play_note(48, 1, 0, 100)
change_vol($Zone_A, -500000, 0) if ($Zone_A # -1)
set_event_par_arr($Zone_A, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
set_event_par_arr($Zone_A, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_A)
wait(1000)
attach_zone($Waveform_A, get_event_par($Zone_A, $EVENT_PAR_ZONE_ID), 0)
message("")
end if end function function FUNC_ATTACH_ZONE_B
$Zone_B := play_note(48, 1, 0, 100)
change_vol($Zone_B, -500000, 0) if ($Zone_B # -1)
set_event_par_arr($Zone_B, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
set_event_par_arr($Zone_B, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_B)
wait(1000)
attach_zone($Waveform_B, get_event_par($Zone_B, $EVENT_PAR_ZONE_ID), 0)
message("")
end if end function {ON UI CONTROLS}
{ON UI CONTROLS - MENU A + B}
on ui_control ($Menu_A)
$Count_Menu_A := 0
while ($Count_Menu_A <= $Menu_A_LAST)
purge_group($Count_Menu_A, 0)
inc($Count_Menu_A)
end while purge_group($Menu_A, 1)
purge_group($Menu_B, 1)
call FUNC_ATTACH_ZONE_A end on on ui_control ($Menu_B)
$Count_Menu_B := 0
while ($Count_Menu_B <= $Menu_B_LAST)
purge_group($Count_Menu_B, 0)
inc($Count_Menu_B)
end while purge_group($Menu_A, 1)
purge_group($Menu_B, 1)
call FUNC_ATTACH_ZONE_B end on {ON PERSISTENCE} on persistence_changed
wait(10000)
call FUNC_ATTACH_ZONE_A
call FUNC_ATTACH_ZONE_B
end on

Comments

  • MTC84
    MTC84 Member Posts: 71 Member

    I should add, I plan on having a lot more groups than 4 - this is just a test to get the code working.

  • theodorech
    theodorech Member Posts: 73 Member

    The overall order of the attach_zone code should be like that:

    1. trigger the temporary event
    2. execute the EVENT_PAR_ALLOW_GROUP code
    3. bring the volume of the generated event down (change_vol or EVENT_PAR_VOLUME)
    4. do the wait(10) thing
    5. add the if statement
    6. attach the zone (attach_zone)

    Note that both menus return 0 at the moment, meaning that the second waveform will be assigned to group 0.

  • MTC84
    MTC84 Member Posts: 71 Member
    edited June 2024

    Thanks for your help.

    I'm not clear on what I am missing but have had a play around with this:

    function FUNC_ATTACH_ZONE_A
    $Event_A := play_note (60, 1, 0, 1) 
    change_vol($Event_A, -500000, 0)

    set_event_par_arr($Event_A, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($Event_A, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_A)
    wait(1000)
    $Zone_A := get_event_par($Event_A, $EVENT_PAR_ZONE_ID)
    attach_zone($Waveform_A, $Zone_A, 0) end function function FUNC_ATTACH_ZONE_B $Event_B := play_note (60, 1, 0, 1)
    change_vol($Event_B, -500000, 0)

    set_event_par_arr($Event_B, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($Event_B, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_B)
    wait(1000)
    $Zone_B := get_event_par($Event_B, $EVENT_PAR_ZONE_ID)
    attach_zone($Waveform_B, $Zone_B, 0) end function

    This doesn't attach the correct zone to each Menu either. Any ideas?

    You mentioned that both Menu A + B return Group 0. I'm not sure how to fix this part.

    Thanks again.

  • theodorech
    theodorech Member Posts: 73 Member

    You forgot to add your if statement. Additionally, both Menu_A and Menu_B are currently set to 0 as the group index. You'll need to either adjust the menu index when you use the add_menu_item code or increment the Menu_B index by adding one (Menu_B + 1). I think you should check one more time the steps I provided above and make sure you also check my little note carefully. Cheers!

  • MTC84
    MTC84 Member Posts: 71 Member

    I think I am there. I need to do some further testing but all appears correct now.

    I actually had to increment the group index by +2 (I have 4 groups in this tester). I will have to change that number when I build the full instrument to reflect the 200 groups/zones.

    Thank you so much for the help. You are awesome.

  • MTC84
    MTC84 Member Posts: 71 Member

    After some testing, I noticed I am getting an error for the 2 lines below but the UI seems to be behaving as it should so I'm not sure what is going on. Groups are loaded and purged as they should be. The correct zone is displayed for both Waveform A + B. The Menu's both work perfectly. Any ideas what I am missing?

    Thanks!

    {ATTACH WAVEFORM ZONE A + B}
    function FUNC_ATTACH_ZONE_A
    $Event_A := play_note (60, 1, 0, 1) 

    set_event_par_arr($Event_A, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($Event_A, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_A)

    change_vol($Event_A, -500000, 0)

    wait(1000) if ($Zone_A # -1)
    set_event_par_arr($Zone_A, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($Zone_A, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_A)
    wait(1000)
    attach_zone($Waveform_A, get_event_par($Zone_A, $EVENT_PAR_ZONE_ID), 0) {ERROR ON THIS LINE}
    end if $Zone_A := get_event_par($Event_A, $EVENT_PAR_ZONE_ID)
    attach_zone($Waveform_A, $Zone_A, 0) end function function FUNC_ATTACH_ZONE_B $Event_B := play_note (60, 1, 0, 1)

    set_event_par_arr($Event_B, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($Event_B, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_B +2)

    change_vol($Event_B, -500000, 0)

    wait(1000) if ($Zone_B # -1)
    set_event_par_arr($Zone_B, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($Zone_B, $EVENT_PAR_ALLOW_GROUP, 1, $Menu_B +2)
    wait(1000)
    attach_zone($Waveform_B, get_event_par($Zone_B, $EVENT_PAR_ZONE_ID), 0) {ERROR ON THIS LINE}
    end if $Zone_B := get_event_par($Event_B, $EVENT_PAR_ZONE_ID)
    attach_zone($Waveform_B, $Zone_B, 0) end function

  • theodorech
    theodorech Member Posts: 73 Member

    It seems that you edited the event's name. If it has to be Event_A, you should address that change to the rest of the script related to that event. Example: most likely, Zone_A event doesn't exist. You should change that to Event_A. Side note: you have too much waiting statements. You simply need one to retrieve the zone's waveform. Check the steps I sent you before :)

  • MTC84
    MTC84 Member Posts: 71 Member

    Finally error free! Thank you so much for all your help. I wouldn't have got the answer without you. You're a legend.

    I am using Zone_A to address something else in the script. It confused the hell out of me but all is working perfectly now.

    My last challenge is sorting the start position and marker on the waveform. I can start a new discussion if needs be but in basic:

    I have coded a MIDI CC to adjust the sample start positions and update a visual marker on the waveform to show the user visually. This works as it should. The playhead positions also work for both waveforms A + B.

    However, I have an issue - Say Menu A has 100 samples within it and each sample varies in length, the start position marker on my waveform graphic doesn't line up with the actual start position.

    If the samples are all say 10secs long, there is no issue. The marker and start position line up.

    I'll probably use equal length samples in every group as a work around. This is a drone type instrument but it would be nice to code this so the marker adjusts automatically to the loaded sample's length if that make sense?

    Is this possible? Is it a simple task or overly complicated?

    Thanks again for everything.

  • theodorech
    theodorech Member Posts: 73 Member

    You’d possibly use the get_sample_length() or a constant modulator to adjust the starting point of the sample. The first might need some extra calculation in order to scale the accurate point of the starting point (visually) and the latter is more straight forward.

  • MTC84
    MTC84 Member Posts: 71 Member

    Thanks. I will do some research and head down the rabbit hole.

This discussion has been closed.
Back To Top