| Hey Michael,
Thanks for the extra notes. I think I've got a good handle on this
though it does require restructuring my original code (to make it
easier to keep the orchestra and score bits clean of other data).
And you're right, it might not be something I really need now. But as
my gui develops and as the project overall evolves these things might
come into play. One of the things that excites me about Csound is how
much power it has built in which opens up so many possibilities. I
might as well learn about these things now so that future development
can be better informed. So while right now my software creates full
pieces, I see no reason why it might not evolve the ability to create
stuff live and allow immediate user interaction.
So many possibilities ...
Dave
On Sat, Dec 31, 2016 at 7:30 PM, Michael Gogins
wrote:
> Any function of the Csound "C" API can be called by luaffi or LuaJIT.
> You just need to provide the function signature as a cdef.
>
> The question is, does using the API over shelling out to the operating
> system get you anything? Basically, that depends on whether, once the
> Csound performance has started, you want to give the user of your
> program real-time control over the performance, e.g. by using sliders
> or knobs to control the sounds of the Csound instruments, or even
> initiating and controlling compositional processes in real time (see
> this for an example of that:
> https://gogins.github.io/csound/Scrims_pnacl.html).
>
> If you don't need real-time control, the API introduces a little bit
> of extra complexity that you may not need. If you do want real-time
> control, the example I gave you already shows what to do. I'll explain
> a little more. The steps are:
>
> -- Create an instance of Csound.
> local csound = csoundApi.csoundCreate(voidptr)
> -- Set the options for the Csound performance. These could come from a
> configuration file, command options, or a GUI form.
> csoundApi.csoundSetOption(csound, '--sample-accurate')
> csoundApi.csoundSetOption(csound, '--output=dac')
> csoundApi.csoundSetOption(csound, '--format=float')
> csoundApi.csoundSetOption(csound, '--nodisplays')
> -- Instead of using a CSD file, we separate the orchestra and the score.
> -- Your program uses a built-in orchestra, or has a library of
> orchestras from which the user selects, or has
> -- a library of Csound instruments that the user builds into a orchestra.
> result = csoundApi.csoundCompileOrc(csound, orchestra_string)
> -- Your code generates the score here and sends it to Csound.
> result = csoundApi.csoundReadScore(csound, score_text)
> -- This tells Csound to start the performance timer and open the
> device drivers and whatnot.
> result = csoundApi.csoundStart(csound)
> -- This is the actual performance loop. The program calls Csound to
> perform one kperiod of audio at a time.
> -- csoundPerformKsmps returns true when the performance has completed.
> while csoundApi.csoundPerformKsmps(csound)== 0 do
> -- You put some code in here, for example to pull channel names
> and values off a queue that
> -- events generated by widgets in your user interface have pushed
> onto the queue. Both Csound and Lua are
> -- plenty fast enough to to sophisticated stuff in real time.
> csoundApi.csoundSetControlChannel(csound, channel_name, channel_value)
> end
>
> Regards
> Mike
>
> -----------------------------------------------------
> Michael Gogins
> Irreducible Productions
> http://michaelgogins.tumblr.com
> Michael dot Gogins at gmail dot com
>
>
> On Sat, Dec 31, 2016 at 7:39 PM, David Bellows wrote:
>> Or it occurs to me that maybe I'm supposed to assemble the Csound file
>> entirely via the API? Regardless some kind of hints would be much
>> appreciated!
>>
>> On Sat, Dec 31, 2016 at 4:12 PM, David Bellows wrote:
>>> Hey Michael, from my limited understanding using the ffi approach also
>>> makes it easier to add C functions later on should I need the increase
>>> in processing speed, right?
>>>
>>> So at this point, do you have some simple instructions about what kind
>>> of code to add to my software to call luaCsnd6 and get it to work? I'm
>>> looking at your csound_luaffi.lua file and I'm having trouble
>>> understanding much of it.
>>>
>>> If you recall my software creates a full .csd file that can be played
>>> with Csound from the command line. So what am I looking at in order to
>>> compile that file from within my Lua file (so that it's supposed to
>>> play back the audio it will or compile a wave file it will, etc)? I'm
>>> playing around with things but having no luck so far.
>>>
>>> Thanks!
>>>
>>> On Sat, Dec 31, 2016 at 3:11 PM, Michael Gogins
>>> wrote:
>>>> That's great, and it's also great that Eric Schulz is helping you.
>>>>
>>>> The main point of using the Csound API is that it gives you the power to
>>>> call and control Csound while it is running in a simple way. LuaCsnd6 and
>>>> FFI both enable this. Which approach is best? That depends on which turns
>>>> out to work best in practice. And that includes which is easiest to extend,
>>>> to maintain, etc. At this point I would lean towards FFI.
>>>>
>>>> Regards,
>>>> Mike
>>>>
>>>>
>>>> On Dec 31, 2016 5:26 PM, "David Bellows" wrote:
>>>>
>>>> Hey Michael, I was just in the process (and failing) of making my
>>>> software LuaJIT compatible.
>>>>
>>>> Ok, I followed your directions and success! But, I the first time
>>>> through I got this warning and which point compilation stopped:
>>>>
>>>> In file included from call.c:38:0:
>>>> dynasm/dasm_x86.h: In function ‘dasm_put’:
>>>> dynasm/dasm_x86.h:207:2: error: this ‘if’ clause does not guard...
>>>> [-Werror=misleading-indentation]
>>>> if (*p++ == 1 && *p == DASM_DISP) mrm = n; continue;
>>>> ^~
>>>> dynasm/dasm_x86.h:207:45: note: ...this statement, but the latter is
>>>> misleadingly indented as if it is guarded by the ‘if’
>>>> if (*p++ == 1 && *p == DASM_DISP) mrm = n; continue;
>>>> ^~~~~~~~
>>>> cc1: all warnings being treated as errors
>>>> Makefile:49: recipe for target 'call.o' failed
>>>> make[1]: *** [call.o] Error 1
>>>> make[1]: Leaving directory '/home/dave/build/luaffi/luaffi'
>>>> Makefile:23: recipe for target 'all' failed
>>>> make: *** [all] Error 2
>>>>
>>>> So I removed the -Werror and get that warning but now it plays:
>>>>
>>>> lua5.3 csound_luaffi.lua
>>>>
>>>> (wonderful Csound music and information flows forth)
>>>>
>>>> This is amazing!
>>>>
>>>> I have no idea where we stand now!
>>>>
>>>> Are you familiar with Eric Shulz? He created this program called
>>>> luastatic that allows one to create a packaged version of one's Lua
>>>> scripts along with whatever version of the Lua interpreter one needs
>>>> for one's platform. He's been helping me with that aspect of things
>>>> and has also managed to get luaCsnd6 working with Lua 5.3. But I don't
>>>> know how or what it all means!
>>>>
>>>> On Sat, Dec 31, 2016 at 12:34 PM, Michael Gogins
>>>> wrote:
>>>>> I got it to work.
>>>>>
>>>>> The good news is, I got the original version of luaffi to build and to
>>>>> work with Lua 5.3, including running Csound through the API using FFI.
>>>>>
>>>>> The bad news is, it does not just happen "out of the box." But it was
>>>>> not so hard.
>>>>>
>>>>> In short, luaffifb (the newer Facebook version of luaffi) is not
>>>>> suitable because it uses luarocks to build, and luarocks does not work
>>>>> "out of the box" with Lua 5.3.
>>>>>
>>>>> But luaffi (the original version of luaffi) does not use luarocks. I
>>>>> was able to patch the code to get luaffi built and run it. The
>>>>> attached document explains how to do it in more detail. Not all of the
>>>>> tests passed but C runtime library functions appear to be called
>>>>> successfully. That's enough for a start.
>>>>>
>>>>> I then took my original example piece for how to use LuaJIT to run the
>>>>> Csound API, changed it very slightly to load luaffi's local build of
>>>>> ffi.so, and it ran just fine without any other changes. The piece is
>>>>> also attached.
>>>>>
>>>>> I _think_ doing this was easier than fooling around building and
>>>>> configuring luarocks and luaffifb.
>>>>>
>>>>> By the way, this kind of thing is one of the reasons that I started
>>>>> using JavaScript. That language truly is standardized and old stuff
>>>>> doesn't break.
>>>>>
>>>>> Regards,
>>>>> Mike
>>>>>
>>>>>
>>>>> -----------------------------------------------------
>>>>> Michael Gogins
>>>>> Irreducible Productions
>>>>> http://michaelgogins.tumblr.com
>>>>> Michael dot Gogins at gmail dot com
>>>>>
>>>>>
>>>>> On Sat, Dec 31, 2016 at 1:11 PM, Michael Gogins
>>>>> wrote:
>>>>>> I have downloaded the platonic music engine from git and run some of
>>>>>> the examples.
>>>>>>
>>>>>> I see that the need for Lua 5.3 arises from the use of bitwise
>>>>>> operations with overloaded operators.
>>>>>>
>>>>>> It would be possible to redo this code to use LuaJIT's "bit" module
>>>>>> for bitwise operations but it uses functions not operators. See if
>>>>>> that looks like too much work.
>>>>>>
>>>>>> I have't yet got luaffifb (current version of luaffi) or alien to work
>>>>>> with Lua 5.3 but I will keep trying.
>>>>>>
>>>>>> Regards,
>>>>>> Mike
>>>>>>
>>>>>> -----------------------------------------------------
>>>>>> Michael Gogins
>>>>>> Irreducible Productions
>>>>>> http://michaelgogins.tumblr.com
>>>>>> Michael dot Gogins at gmail dot com
>>>>>>
>>>>>>
>>>>>> On Sat, Dec 31, 2016 at 7:52 AM, Michael Gogins
>>>>>> wrote:
>>>>>>> QtCreator in the Qt SDK is more complete. Easy to create pieces or
>>>>>>> applications that use Csound via the API. On Windows get the 64 bit
>>>>>>> version.
>>>>>>>
>>>>>>> Now that I think of it, you could embed either Lua 5.3 or LuaJIT in such
>>>>>>> programs.
>>>>>>>
>>>>>>> Regards,
>>>>>>> Mike
>>>>>>>
>>>>>>> On Dec 31, 2016 4:57 AM, "Richard" wrote:
>>>>>>>>
>>>>>>>> I recently discovered Code::Blocks, a free and cross platform c/c++
>>>>>>>> IDE,
>>>>>>>> compiler, debugger. It seems very complete.
>>>>>>>>
>>>>>>>> Richard
>>>>>>>>
>>>>>>>>
>>>>>>>> On 30/12/16 23:33, Michael Gogins wrote:
>>>>>>>>>
>>>>>>>>> For simple programs you don't need a build system at all. Just keep
>>>>>>>>> all your code in one .c or .cpp file and compile with a simple .bat
>>>>>>>>> file or .sh script. For example the following command builds a C
>>>>>>>>> program that uses the Csound API on Linux:
>>>>>>>>>
>>>>>>>>> gcc memory_leak.c -O2 -g -lcsound64 -I../include -I../H -omemory_leak
>>>>>>>>>
>>>>>>>>> It's basically just as easy to compile a Lua extension module. Most
>>>>>>>>> people have no idea how much code you can get into one .c or .cpp
>>>>>>>>> file. At some point you might have to tell the compiler to use more
>>>>>>>>> memory or something. For example, the LuaJIT build system has an
>>>>>>>>> option to compile all of LuaJIT as just one .c file.
>>>>>>>>>
>>>>>>>>> Now that I understand your workflow, better not to use the FLTK
>>>>>>>>> opcodes but rather use a GUI toolkit that works with Lua 5.3.
>>>>>>>>>
>>>>>>>>> luaCsnd6 does work with Lua 5.1 or LuaJIT, it just doesn't work with
>>>>>>>>> Lua 5.3 and I have no intention of getting it to work myself because
>>>>>>>>> that would conflict with LuaJIT which I continue to use.
>>>>>>>>>
>>>>>>>>> However, as I said, I will try to get Lua 5.3 with luaffi to call the
>>>>>>>>> Csound API. I see from a later email of yours that you got tekui to
>>>>>>>>> work with Lua 5.3. So I think luaffi could solve your problem.
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>> Mike
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -----------------------------------------------------
>>>>>>>>> Michael Gogins
>>>>>>>>> Irreducible Productions
>>>>>>>>> http://michaelgogins.tumblr.com
>>>>>>>>> Michael dot Gogins at gmail dot com
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Fri, Dec 30, 2016 at 4:14 PM, David Bellows
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Michael,
>>>>>>>>>>
>>>>>>>>>>> I think you were wrong about C, C is easier than Lua.
>>>>>>>>>>
>>>>>>>>>> I'm sure you are correct! I've been using Linux exclusively since
>>>>>>>>>> 1998
>>>>>>>>>> and I've compiled many, many programs (including kernels -- back in
>>>>>>>>>> the day). But when I look at that process and dare venture into the
>>>>>>>>>> makefiles I become befuddled. So maybe the language itself is easier
>>>>>>>>>> but the compilation process is definitely intimidating looking!
>>>>>>>>>>
>>>>>>>>>> That said, my software operates in two levels. The lower level is all
>>>>>>>>>> functions like generating tunings (audio frequencies), generating
>>>>>>>>>> notes of a scale, etc. The higher level are the specific musical
>>>>>>>>>> ideas
>>>>>>>>>> that the user wants to generate (like a Bach prelude or serialism,
>>>>>>>>>> etc). So the user runs the higher level musical ideas ("Style
>>>>>>>>>> Algorithms") which call all the low level functions as needed. I'm
>>>>>>>>>> guessing that sooner or later I'm going to rewrite all those low
>>>>>>>>>> level
>>>>>>>>>> functions in C while the Style Algorithms will remain in Lua. This
>>>>>>>>>> allows people to more easily contribute Style Algorithms (like game
>>>>>>>>>> mods) and will be more in line with the Lua way of doing things.
>>>>>>>>>>
>>>>>>>>>>> FLTK should be fine for your GUIs. To use Lua 5.3 with Csound
>>>>>>>>>>
>>>>>>>>>> (including the FLTK opcodes) via the shell is no problem at all.
>>>>>>>>>>
>>>>>>>>>> Awesome! Are there any tutorials you can point to? The reference
>>>>>>>>>> manual is tricky to figure out sometimes and I've been struggling.
>>>>>>>>>> Especially since I'm not wanting to generate any instrument data,
>>>>>>>>>> just
>>>>>>>>>> a GUI.
>>>>>>>>>>
>>>>>>>>>> And I imagine that for now I could start with a Lua script which
>>>>>>>>>> would
>>>>>>>>>> call a Csound GUI which would then pass values (via an external file)
>>>>>>>>>> back to the Lua script which would then generate all the data and
>>>>>>>>>> create a Csound file and then call Csound again with a new GUI to
>>>>>>>>>> play
>>>>>>>>>> it and stuff. Just thinking ...
>>>>>>>>>>
>>>>>>>>>> If you can get the luaCsnd6 to work in Lua I will be forever
>>>>>>>>>> grateful!
>>>>>>>>>> That would open many cool doors for me.
>>>>>>>>>>
>>>>>>>>>> Thanks!
>>>>>>>>>> Dave
>>>>>>>>>>
>>>>>>>>>> On Fri, Dec 30, 2016 at 12:04 AM, Francesco Porta
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>> Hello Dave,
>>>>>>>>>>> i understand you, as i said i am a Lua and Csound user without
>>>>>>>>>>> programming knowledge.
>>>>>>>>>>> Sometimes is so frustrating do not understand, but same is for life
>>>>>>>>>>> :)
>>>>>>>>>>> Anyway my last attempt to be helpful.
>>>>>>>>>>> Have you see this:
>>>>>>>>>>> http://tekui.neoscientists.org/
>>>>>>>>>>> it seems nice and should work with Lua 5.3.
>>>>>>>>>>> Maybe could be a possibility.
>>>>>>>>>>>
>>>>>>>>>>> ciao,
>>>>>>>>>>> francesco.
>>>>>>>>>>>
>>>>>>>>>>> Csound mailing list
>>>>>>>>>>> Csound@listserv.heanet.ie
>>>>>>>>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>>>>>>>>>> Send bugs reports to
>>>>>>>>>>> https://github.com/csound/csound/issues
>>>>>>>>>>> Discussions of bugs and features can be posted here
>>>>>>>>>>
>>>>>>>>>> Csound mailing list
>>>>>>>>>> Csound@listserv.heanet.ie
>>>>>>>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>>>>>>>>> Send bugs reports to
>>>>>>>>>> https://github.com/csound/csound/issues
>>>>>>>>>> Discussions of bugs and features can be posted here
>>>>>>>>>
>>>>>>>>> Csound mailing list
>>>>>>>>> Csound@listserv.heanet.ie
>>>>>>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>>>>>>>> Send bugs reports to
>>>>>>>>> https://github.com/csound/csound/issues
>>>>>>>>> Discussions of bugs and features can be posted here
>>>>>>>>
>>>>>>>>
>>>>>>>> Csound mailing list
>>>>>>>> Csound@listserv.heanet.ie
>>>>>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>>>>>>> Send bugs reports to
>>>>>>>> https://github.com/csound/csound/issues
>>>>>>>> Discussions of bugs and features can be posted here
>>>>>
>>>>> Csound mailing list
>>>>> Csound@listserv.heanet.ie
>>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>>>> Send bugs reports to
>>>>> https://github.com/csound/csound/issues
>>>>> Discussions of bugs and features can be posted here
>>>>
>>>> Csound mailing list
>>>> Csound@listserv.heanet.ie
>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>>>> Send bugs reports to
>>>> https://github.com/csound/csound/issues
>>>> Discussions of bugs and features can be posted here
>>>>
>>>>
>>>> Csound mailing list Csound@listserv.heanet.ie
>>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>>> https://github.com/csound/csound/issues Discussions of bugs and features can
>>>> be posted here
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>> Send bugs reports to
>> https://github.com/csound/csound/issues
>> Discussions of bugs and features can be posted here
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
> https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here |