Csound Csound-dev Csound-tekno Search About

[Csnd] Scope of csoundApi variable in Lua

Date2013-07-17 18:39
FromMark Brophy
Subject[Csnd] Scope of csoundApi variable in Lua
I want to use the wxLua widgets library to schedule score events using csoundReadScore and csoundScoreEvent in Lua, but after I run csoundApi = ffi.load('csound64') inside a function, the csoundApi variable becomes nil after the function terminates even though the variable is global. How can I initialize Csound in one function and run score events based on user input, wxLua, in another function?


Date2013-07-17 20:18
Fromfrancesco
Subject[Csnd] Re: Scope of csoundApi variable in Lua
Hello,
not an answer but You can use the Csound API in Lua/LuaJIT using
require "luaCsnd6"
and the CsoundAC API with
require "luaCsoundAC" (if i'm correct).

This is the simplest way to use Csound in Lua/LuaJIT, i guess.
But maybe You already know that and need something different.
Anyway, if matter below is a simple example for Python by Mr. Lazzarini
translated for Lua

ciao,
francesco.

require "luaCsnd6"

cs = luaCsnd6.Csound()
cs:SetOption("-+rtaudio=alsa")
cs:SetOption("--nchnls=2")
cs:SetOption("-d")
cs:SetOption("-odac")
cs:Start()

perf = luaCsnd6.CsoundPerformanceThread(cs)
perf:Play()

for i=1, 10 do
    cs:CompileOrc([[
event_i "i", 1, 0, 1, 5000, 500
event_i "i", 1, 0.25, 1, 5000, 500
instr 1
k1 expon 1, p3, 0.001
a2 oscili k1*p4, p5,-1
outs a2, a2
endin
]])

    luaCsnd6.csoundSleep(500)
end

perf:Stop()





--
View this message in context: http://csound.1045644.n5.nabble.com/Scope-of-csoundApi-variable-in-Lua-tp5725736p5725737.html
Sent from the Csound - General mailing list archive at Nabble.com.

Date2013-07-18 03:41
FromMark Brophy
SubjectRe: [Csnd] Re: Scope of csoundApi variable in Lua
Thanks for the help. I haven't been using a performance thread so that might help me solve the problem.

On Wed, Jul 17, 2013 at 1:18 PM, francesco <ilterzouomo@fastwebnet.it> wrote:
Hello,
not an answer but You can use the Csound API in Lua/LuaJIT using
require "luaCsnd6"
and the CsoundAC API with
require "luaCsoundAC" (if i'm correct).

This is the simplest way to use Csound in Lua/LuaJIT, i guess.
But maybe You already know that and need something different.
Anyway, if matter below is a simple example for Python by Mr. Lazzarini
translated for Lua

ciao,
francesco.

require "luaCsnd6"

cs = luaCsnd6.Csound()
cs:SetOption("-+rtaudio=alsa")
cs:SetOption("--nchnls=2")
cs:SetOption("-d")
cs:SetOption("-odac")
cs:Start()

perf = luaCsnd6.CsoundPerformanceThread(cs)
perf:Play()

for i=1, 10 do
    cs:CompileOrc([[
event_i "i", 1, 0, 1, 5000, 500
event_i "i", 1, 0.25, 1, 5000, 500
instr 1
k1 expon 1, p3, 0.001
a2 oscili k1*p4, p5,-1
outs a2, a2
endin
]])

    luaCsnd6.csoundSleep(500)
end

perf:Stop()





--
View this message in context: http://csound.1045644.n5.nabble.com/Scope-of-csoundApi-variable-in-Lua-tp5725736p5725737.html
Sent from the Csound - General mailing list archive at Nabble.com.


Send bugs reports to the Sourceforge bug tracker
            https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"