Ooookay… i think/guess/hope that i have now a version which works as it should.
To circumvent the “rebellious behaviour” of the audio player (i guess there will be some bugs fixed for the next release of GP), i used a group of hidden LED widgets to somehow “buffer” the actual state of the most important widgets, so their state can be recalled correctly when having changed audioplayer files or having changed rackspaces.
A new feature is the “auto recognition” for the caption of the text label!
This will automatically be created from the actual variation name which will be cut at the beginning according to the repeating naming pattern… in this example the naming pattern for the variations is
“Audio - Track A-1” where the repeating substring to be cut away will be "Audio - " (this string can be changed in the script!), so the resulting name would be “Track A-1”… in addition to this i also placed the actual variation index before the name, means the final caption for the text label would display “1: Track A-1”
Another example:
If you would rename the third variation to (i.e.) “Audio - The Wall” then the label would be automatically set to “3: The Wall” (note: you will have to change to another variation and back to have the change take effect)
Now this rackspace is flexible enough to be just duplicated without having to make changes within the script - except you want to change header of the naming pattern .
On some places the code could be improved/shortened but on other places some additional code was needed…
This is the script code:
var
switch_mode, switch_radio, btn_loop, btn_reset, btn_play, btnPlayerOpen : Widget
lbl_pos, L1 : Widget
trk_1, trk_2, trk_3, trk_4, trk_5, trk_6, trk_7, trk_8 :Widget
buttons : Widget Array = [trk_1, trk_2, trk_3, trk_4, trk_5, trk_6, trk_7, trk_8]
//hidden buffer widgets to store and recall the state of the "real" widgets
buff_mode, buff_loop, buff_radio, buff_t1, buff_t2, buff_t3, buff_t4, buff_t5, buff_t6, buff_t7, buff_t8 : widget
buffers : widget array =[buff_mode, buff_loop, buff_radio, buff_t1, buff_t2, buff_t3, buff_t4, buff_t5, buff_t6, buff_t7, buff_t8]
//Use this string to set what is "cut" from the begin of the Variation name
//The rest of the string then will be used as the caption of the test label
LabelHeader : string = "Audio - "
Function ResetAndPlay (btn_state : double)
if GetWidgetValue (switch_radio) == 1.0 and btn_state ==1.0 and GetWidgetValue (btn_play) == 1.0 then
SetWidgetValue (lbl_pos, 0.0)
SetWidgetValue (btn_play, 1.0)
end
End
Function ResetButtons()
var i, counter : integer
counter = 0
for i = 0; i < Size(buttons); i = i + 1 do
if GetWidgetValue (buttons[i]) > 0.55 then
counter = counter+1
end
end
if counter >1 or counter ==0 then
for i = 0; i < Size(buttons); i = i + 1 do
SetWidgetValue (buttons[i], 0.0)
end
SetWidgetValue (buttons[0], 1.0)
end
End
function SetLabelText()
var
variName, lblText : string
variName = GetVariationName(GetCurrentVariation())
lblText = "" + (GetCurrentVariation() +1) + " : " + CopySubstring(variName, Length(LabelHeader), Length(variName)-Length(LabelHeader))
SetWidgetLabel(L1, lblText)
End
//function to buffer the state of the active widgets with hidden passive widgets
function WidgetStateSafe (mode : string) //mode can be "store" or "recall"
var i:integer
If mode == "store" then
SetWidgetValue(buffers[0], GetWidgetValue (switch_mode))
SetWidgetValue(buffers[1], GetWidgetValue (btn_loop))
SetWidgetValue(buffers[2], GetWidgetValue (switch_radio))
For i=3;i<Size(buffers);i=i+1 Do
SetWidgetValue(buffers[i], GetWidgetValue (buttons[i-3]))
end
Elsif mode == "recall" then
SetWidgetValue(switch_mode, GetWidgetValue(buffers[0]))
SetWidgetValue(btn_loop, GetWidgetValue(buffers[1]))
SetWidgetValue(switch_radio, GetWidgetValue(buffers[2]))
For i=3;i<Size(buffers);i=i+1 Do
SetWidgetValue (buttons[i-3],GetWidgetValue(buffers[i]))
end
end
End
Initialization
SetWidgetValue (btn_reset, 1.0)
SetWidgetValue (btn_play, 0.0)
SetLabelText()
WidgetStateSafe("store")
End
On Activate
SetLabelText()
WidgetStateSafe("recall")
End
on Variation (oldVariation:integer, newVariation:integer)
SetLabelText()
End
On WidgetValueChanged (newval : double) from btn_reset
if newval == 1.0 and GetWidgetValue (btn_loop) == 0.0 then
SetWidgetValue (btn_play, 0.0)
SetWidgetValue (lbl_pos, 0.0)
elsif newval == 1.0 and GetWidgetValue (btn_loop) == 1.0 then
SetWidgetValue (lbl_pos, 0.0)
SetWidgetValue (btn_reset, 0.0)
end
End
On WidgetValueChanged (newval : double) from btn_play
if newval == 1.0 then
SetWidgetValue (btn_reset, 0.0)
end
End
On WidgetValueChanged (newval : double) from btnPlayerOpen
if newval >0.55 then
WidgetStateSafe("store")
else
WidgetStateSafe("recall")
end
End
On WidgetValueChanged (newval : double) from switch_mode
if newval == 0.0 and GetWidgetValue (switch_radio) == 1.0 then
SetWidgetValue (switch_radio, 0.0)
Elsif newval == 1.0 then
ResetButtons()
end
WidgetStateSafe("store")
End
On WidgetValueChanged (newval : double) from switch_radio
if newval == 1.0 and GetWidgetValue (switch_mode) == 0.0 then
SetWidgetValue (switch_radio, 0.0)
end
WidgetStateSafe("store")
End
On WidgetValueChanged (newval : double) from trk_1, trk_2, trk_3, trk_4, trk_5, trk_6, trk_7, trk_8
ResetAndPlay(newval)
WidgetStateSafe("store")
End
And this is the new gig file (i hope it works as expected):
audioplayer_V4_autolabel.gig (1.7 MB)
May it be helpful!
Cheers!
Erik