View Single Post
Old 03-28-2019, 10:49 PM   #418
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
Default can't get value from gui.Val

I'm trying to test a method by modifying one of the example scripts (as little as possible) It just adds a send or two, and changes a parameter in a jsfx.

But however I try to get the value of the slider, It always crashes the script, and the trace doesn't show the value of it.

Is there a simpler way to get the value of a slider than to override mouse methods anyway? I couldn't find one. The button object has a built-in method, but none of the others seem to.... I'm used to adding a listener, but I don't see any equivalent here.

I also tried calling my method with self.Val as an argument from within the double-click method, instead of trying to get it from within my method and that allowed me to get the slider's value printed to the console before the crash.... it said 'nil'.

Here's the trace:
Code:
Test_Attempt_2.lua:59: in upvalue 'setNotesource'
	Test_Attempt_2.lua:179: in method 'ondoubleclick'
	Core.lua:843: in field 'Update'
	Core.lua:434: in field 'Main_Update_Elms'
	Core.lua:301: in function <...am Scripts\Development\Lokasenna_GUI v2\Library\Core.lua:297>
		[C]: in function 'xpcall'
	Core.lua:297: in function <...am Scripts\Development\Lokasenna_GUI v2\Library\Core.lua:296>

Lokasenna_GUI:	v2.16.3
Reaper:       	5.972/x64
Platform:     	Win64
And here's the code:

Code:
-- NoIndex: true

--[[
	Lokasenna_GUI

- Using the Main loop to monitor and interact with things in Reaper
	- Using z layers and related functions to move elements around
	- Changing elements' methods for your own purposes

]]--

-- The Core library must be loaded prior to anything else

local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Script: Set Lokasenna_GUI v2 library path.lua' in your Action List.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()

dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")

GUI.req("Classes/Class - Label.lua")()
GUI.req("Classes/Class - Slider.lua")()
GUI.req("Classes/Class - Frame.lua")()

-- If any of the requested libraries weren't found, abort the script.
if missing_lib then return 0 end




------------------------------------
-------- Data + functions ----------
------------------------------------


-- Pre-declaring this so every function has access to it
local tr


local function update_pan()
	
	--reaper.SetMediaTrackInfo_Value( tr, "D_PAN", GUI.Val("sldr_pan")/100 )
	
end

local function addMidiReceive(tracknumber,srcChan)
    --set to midi input (1024)
    added = ultraschall.AddTrackAUXSendReceives(tracknumber,srcChan,
                                        0,0,0,0,0,0,1,1,-1,1024,-1,false)
    if added then return added 
    else ultraschall.print2("problem setting midi receive from track "
        ..tostring(srcChan).." to track "..tostring(tracknumber))
    end
end

local function setNotesource()
    nsIndex = gui.Val("sldr_pan")
    reaper.ShowConsoleMsg("nsrc = "..tostring(nsIndex))  
    tracknumber = 16
    PIANO = 1
    ROLI = 2
    DUAL = 3
    NONE = 4

    OUTPUT_A_TRACKNUM = 1
    OUTPUT_B_TRACKNUM = 2
    OUTPUT_C_TRACKNUM = 3
    OUTPUT_D_TRACKNUM = 4
    PIANO_TRACKNUM = 5
    ROLI_TRACKNUM = 6

    MIDICHSTRIP_SLOT_NUM = 2
    NS_SELECT_PARAM = 11

    --Get track
    track = reaper.GetTrack(0,tracknumber) 
    if track == nil then ultraschall.print2("invalid track number")
    end
    --ultraschall.print2("track = "..tostring(tracknumber))
    --Get list of sends
    count_Receives = ultraschall.CountTrackAUXSendReceives(tracknumber)
    --check through for those that are midi enabled
    for i = 0, count_Receives do
        _,_,_,_,_,_,_,_,_,_,hasMIDI,_ = ultraschall.GetTrackAUXSendReceives(tracknumber, i)
        if hasMIDI == 1024 then   --setting for all midi enabled
            --remove these sends
            removed = ultraschall.DeleteTrackAUXSendReceives(tracknumber, i, false)
        end
    end
    --add new send(s) to track 1-kx8,2-roli,1&2 dual, none for FX (this is also our check for isFX)
    if nsIndex == PIANO then 
        addMidiReceive(tracknumber,PIANO_TRACKNUM)
    elseif nsIndex == ROLI then  
        addMidiReceive(tracknumber,ROLI_TRACKNUM)
    elseif nsIndex == DUAL then  
        addMidiReceive(tracknumber,ROLI_TRACKNUM)
        addMidiReceive(tracknumber,PIANO_TRACKNUM) 
    else  --do nothing it's an effect... or should we do something?
    end
    --set midiChStrip value for input type
    --reaper.ShowConsoleMsg()
    reaper.TrackFX_SetParam(track,MIDICHSTRIP_SLOT_NUM,NS_SELECT_PARAM,nsIndex)   
    ultraschall.ShowLastErrorMessage()
end




------------------------------------
-------- Window settings -----------
------------------------------------


GUI.name = "Example - Main, Z, and Methods"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 300, 128
GUI.anchor, GUI.corner = "mouse", "C"




------------------------------------
-------- GUI Elements --------------
------------------------------------


--[[	

	Frame		z, 	x, 	y, 	w, 	h[, shadow, fill, color, round]
	Label		z, 	x, 	y,		caption[, shadow, font, color, bg]
	Slider		z, 	x, 	y, 	w, 	caption, min, max, defaults[, inc, dir]
	
]]--

--GUI.New("lbl_track", "Label",	1,	96, 8, "No track selected!", true, 2, "red")
--GUI.New("frm_track", "Frame",	2,	0, 0, 300, 128, false, true, "faded", 0)
GUI.New("sldr_pan", "Slider",	3,	88, 64, 128, "First selected track's NS:", 1, 4, 1, 1, "h")


-- Layer 5 will never be shown or updated
-- (See the Main function below)
GUI.elms_hide[5] = true




------------------------------------
-------- Method overrides ----------
------------------------------------


-- Class methods can be overwritten, either at the class level or
-- for individual elements.

-- You can also easily append your own code to the stock methods:
function GUI.elms.sldr_pan:onmousedown()
	
	-- Run the slider's normal method
	GUI.Slider.onmousedown(self)

	-- Note that we have to call the method as a function here; we
	-- can't use the : syntax because sldr_pan's 'self' needs to be
	-- passed on as a value. If we used a :, it would pass GUI.Slider
    
	
	
end
function GUI.elms.sldr_pan:ondrag()
	GUI.Slider.ondrag(self)
	
end
function GUI.elms.sldr_pan:onwheel()
	GUI.Slider.onwheel(self)
	
end
function GUI.elms.sldr_pan:ondoubleclick()
    GUI.Slider.ondoubleclick(self)
    setNotesource()
    --setNotesource(self.Val)
	
end




------------------------------------
-------- Main loop -----------------
------------------------------------


-- This will be run on every update loop of the GUI script; anything you would put
-- inside a reaper.defer() loop should go here. (The function name doesn't matter)
local function Main()
	
	
	
end


GUI.Init()

-- Tell the GUI library to run Main on each update loop
-- Individual elements are updated first, then GUI.func is run, then the GUI is redrawn
GUI.func = Main

-- How often (in seconds) to run GUI.func. 0 = every loop.
GUI.freq = 0

GUI.Main()
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote