| Hi Michael,
I think I understand a bit more of what you are proposing. However, I
tried to think it through and I have reservations about mapping Csound
into another language's language/runtime. I see the following steps
in current csound orc:
1. ORC Parser reads in ORC, translates to TREE
2. Compiler reads in TREE, creates graph of structs and allocates
variables using hardcoded type system, to create an instruments and
UDO's
3. Csound engine performs
with your proposal, I understand it as:
1a. ORC Parser reads in ORC, translates to Engine Language (Lua, C++, etc.)
1b. User directly creates graph in Engine Language
2. Csound engine runs, using Engine Language Runtime
My gut feeling on this is that it would complicate things in a few ways.
1. This would add a very large dependency. I would imagine that
choices for embedding a language would be Lua (popular for games) and
Scheme (GNU's official scripting language). LuaJIT is a non-starter:
it doesn't work on Mac 64-bit without compiling the application with
special compiler settings and we can't control that for things like
Python or other scripting systems. We would have to find a language
that would run fine on all platforms (including Android and iOS).
Then we have issues about how these might interact in a multi-threaded
environment. It may be fine, it may not, but I imagine it'd take some
time to test/explore.
2. Runtimes could collide. For example, running a python-based
application would have the python runtime in addition to the Engine
Language runtime. With current Csound, the engine is quite small, and
straight C. With introducing another language's runtime as the basis
of the engine, I don't know what to expect. If you code in Lua, then
run Csound, which then uses Lua itself, could there be clashes in
globals, signal handlers, etc? Again, something I'm not sure about,
but it's something of a red-flag. And what of TCL, or Java, or Common
Lisp? It's just a gut feeling, but I feel more sure of straight C
code that is in Csound now that with a new engine runtime based on
another language.
3. As I see it, even if we did define the graph in another language,
we still need to wrap the current variable types, to convert between
the engine language's types into Csound's variable types. If we
rewrote all opcodes to use engine languages types, that'd be expensive
in development time. If we wrap types and use convertors, that would
introduce non-negligible processing load, and we'd still want a
generic type system to ease introduction of new types in Csound ORC,
as well as wrapping.
I can see benefits to be able to define new opcode by the user in a
different language. I can see benefits to creating new instruments
that do all processing in a host-language. I think the path to
modifying Csound to allow these by wrappers and other things makes
sense, but I'm not sure we need to introduce a language runtime to do
this. If the goal is to be able to write a piece in one language, as
well as create instrument and opcodes in that language, as well as to
control the graph and modify it at runtime, I think moving forward
with the generic type system and continuing modifying the API will be
easier to implement, and be simpler architecturally.
I also don't think this is so simple as just reusing some other
language runtime's type system. There is a lot of unknowns I see,
especially with non-desktop platforms, and I don't think the benefits
outweigh the concerns.
Additionally, I don't think a generic type-system will be so big a
thing to develop. One other thing too is that I think it is a safer
option to go this route at this time, because the work involved will
only make Csound more amenable to future changes that could involve
other runtimes.
For now, I will resume work on a generic type-system, but will do so
locally or in a branch. We can then integrate if it's desirable, and
we can continue the conversation. I'd also propose a larger change
such as introducing a language runtime change might be something we
look at for Csound 7 (then I'd rather look at LLVM and hope it only
stabilizes further across platforms).
Thanks! (And please correct if I've misinterpreted anything!)
steven
On Tue, Jun 5, 2012 at 8:23 PM, Michael Gogins wrote:
> Responding to your response... in line.
>
> I'd like to clear some things up first, though. I'm 100% committed to
> complete backward compatibility for all existing Csound compositions.
> So, I'm not proposing to replace the existing orc language. But I am
> proposing to implement the orc compiler by generating the Csound data
> flow graph using a "host language," which could _also_ be used for
> writing pieces, instruments, or opcodes. Being able to write Csound
> pieces, instruments, and opcodes in other languages is a goal of
> Csound 6, no? Here I am simply exploring what seems to me the simplest
> and most efficient way of doing this.
>
> Perhaps the best way to understand this proposal is by analogy with
> C++. When C++ first came along, it was implemented with a compiler
> that did not generate machine code, but rather special C code, which
> was then compiled by the regular C compiler. This actually worked
> rather well. So, what I'm proposing is taking a "host language" and
> writing a SWSS in it that uses the Csound opcodes, then changing the
> Csound orc compiler so that it compiles Csound pieces written in the
> traditional Csound language and syntax into programs in the host
> language. As part of this compilation, there would be a synchronous
> data flow control graph, written in the host language, that reflects
> the current state of the art in such things.
>
> But then, the host language could also be used to write pieces,
> instruments, or opcodes. For some people, that would be a better way
> of writing music. The host language would be a widely used, powerful
> language such as C++, Lua, or whatever. As long as it's fast, robust,
> and genuinely widely used.
>
> On Tue, Jun 5, 2012 at 4:04 PM, Steven Yi wrote:
>
>> As I mentioned before, I do not think the type system proposal hinders
>> embedding, but rather helps enable it more easily. You mention not
>> needing a type system,
>
> Not so, I proposed using the type system of an existing general
> purpose language.
>
>>but I would argue as before that there already
>> is an intrinsic, hard-coded type system in csound. A host language,
>> if creating a graph, would still need a means to connect the opcodes
>> (nodes) to each other through variables (edges). Each edge has a type
>> in Csound, whether that is a-, k-, i-, f-, S-, w-, etc.
>
> The graph would be rewritten in the host language such that it could
> connect the Csound types as well as user-defined types.
> This could be done in C++ for example with template metaprogramming,
> or in Java with generics.
>
>>With a
>> generic type system, one can generate wrappers for each variable type
>> by querying.
>
> As I said, in C++ at compile time by templates, in dynamic languages
> by querying as you say.
>
>>With the current type system, one has to create wrappers
>> manually for each language. This is all for assembling a graph from a
>> host language.
>>
>
> I think it might be simpler to imagine replacing the current semantic
> actions in the Csound orchestra language with new actions that
> generate code in the host language.
>
>> For writing blocks or graphs from a host language, I would imagine
>> this to be clearer:
>>
>> 1. Instrument class, which host language can subclass. In classic
>> Csound, we would instantiate a sub-class CsoundInstrument (well, it'd
>> be a struct with function pointers). Pointers would have init,
>> perform, destroy. Host languages could then just override methods.
>> This would allow creating instruments that runs in Csound's engine
>> that are completely written in a host-language.
>
> Yes, but in what I envision the Csound instrument base class is
> declared in the host language. Either the Csound orchestra compiler,
> or the host language compiler, would both be able to declare,
> subclass, and instantiate Csound instruments deriving from this type.
>
> Let me try to make this a bit clearer... the opcodes would be wrapped
> in the host language, and the Csound data flow graph would not be
> wrapped, it would be replaced by a new data flow graph in the host
> language that could perfectly emulate the topology of the existing
> Csound graph, or be constructed in new topologies.
>
> In other words... supposing that the host language is LuaJIT, the
> Csound graph would be written in Lua and the existing opcodes would
> remain as C and C++ code, but would be called by LuaJIT's foreign
> function interface (not wrapped via SWIG, as that's not as efficient).
> Or, supposing the host language is C++, the Csound graph would be
> written in C++ and the existing opcodes would remain as C and C++
> code.
>
>> 2. Opcode class, which host language can subclass. Host language
>> could then subclass to introduce opcodes written in host-language.
>
> Yes, but there would be 2 ways or writing opcodes: as traditional
> C/C++ Csound opcodes, or in the host language. The Csound graph would
> know how to connect and call both kinds, probably through some kind of
> abstract wrapper class. Host language opcodes would simply implement
> the opcode interface, and traditional Csound opcodes would be wrapped
> in a simple implementation of the interface. The existing C++ opcode
> base class shows how this can be done in C++ with no, I repeat no,
> runtime overhead and considerably easier to read code... similar
> things could be done in LuaJIT.
>
> The examples you give below work fine with what I am saying, if the
> host language is Python.
>
>> The coding styles I see from this (pseudo-python):
>>
>> # Instrument with all methods in python
>> class MyInstr(Instrument):
>> def init(self):
>> super.init(self)
>> ... insert standard python code ...
>>
>> def perform(self):
>> ... do audio code in python, write output for csound to pickup ...
>>
>> def destroy(self):
>> .. free up large resources ...
>>
>> #instrument with Csound graph built in Python
>> class MyInstr2(Instrument):
>> def init(self):
>> super.init(self)
>> ... create graph of csound opcodes...
>> self.rootOp = someOpcode(1,2,3)
>>
>> def perform(self):
>> writeOutput(CsoundGraphPerform(self.rootOp))
>>
>> #Opcode
>> class MyOp(Opcode):
>> def getInArgs(self):
>> return "ak"
>> def getOutArgs(self):
>> return "a"
>> def init(self):
>> super.init(self)
>> def process(self, csound):
>> ...etc...
>>
>> NOTE: MyInstr2 in the above does not perform the graph within the host
>> language, it only sets up the graph, and uses a utility method to
>> perform the graph within C code. Otherwise, to perform manually, you
>> could do something like:
>>
>> def perform(self):
>> self.generator.perform()
>> self.filterPerform.perform()
>> pyVal = self.filterOutput.getValue() // self.filterOutput would be a
>> saved variable of a-type
>> pyVal = doSomethingInPython(pyVal)
>> writeOutput(pyVal)
>
>> One other thing to note: I see having a separate orc language as a
>> pro, not a con. It has to do with point of view; I think
>> historically, it is important that the existing orc language has
>> survived some 20+ years as a means to describe and keep alive a body
>> of musical code. I think practically, having a domain specific
>> language for audio is a good thing and allows sharing audio code
>> across different host languages.
>
> I am not proposing to replace the existing orc language! Horrors! I am
> 100% committed to complete backward compatibility. As I have said, the
> Csound compiler would be able to create the new graph from existing
> orc code.
>
> At the same time, the style in your example could be used to write
> orchestras completely in the host language, including new opcodes. I
> think this would be a tremendous advantage -- it is why I am spending
> so much time explaining this.
>
> In other words, I think we can have our cake, and eat it too. We can
> keep the backward compatibility, and we can create a new SWSS in which
> compositions and opcodes can be written in the same language, which
> would be a real language that more people would know.
>
>> So, I'll say again, I understand the desire to make more of Csound
>> available to a host language to have ways to implement in the host.
>> However, I do not see how one gets around the existing type-system in
>> Csound, nor how a newer type-system would not be an advantage for the
>> goals of more embedding possibilities.
>
> Again, a newer type system is definitely an advantage and I welcome
> your desire to add one, but they already exist, there is no need to
> invent one.
>
> Best,
> Mike
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net |