Csound Csound-dev Csound-tekno Search About

Re: [Cs-dev] scsort and scxtract

Date2005-10-28 19:38
FromMichael Gogins
SubjectRe: [Cs-dev] scsort and scxtract
I am only interested in supporting the second mode. Is that OK with you?

I agree that the code should be changed to omit the requirement for an input score.

As you may or may not be aware, CsoundVST contains a CsoundScore class which facilities for reading, modifying or creating, and writing orc, sco, and csd files. There is obviously some overlap in functionality with CScore. CsoundScore works in the following way: the API user programmatically sets orchestra text, then programmatically adds score lines to the score, then calls CsoundFile::exportForPerformance which writes out an orc and sco file. You then call csoundPerform to render the exported files.

What happens if you call CScore functions while a performance is running? CsoundFile does nothing in this case.

Regards,
Mike

-----Original Message-----
From: Anthony Kozar 
Sent: Oct 28, 2005 2:08 PM
To: New Csound Developer list 
Subject: Re: [Cs-dev] scsort and scxtract

Michael Gogins wrote on 10/27/05 3:45 PM:

> This type of comment is exactly what I meant, yes, and that is the appropriate
> level of detail.

Ok.  I will get around to this eventually.

> As for the CScore API, if you will give me a little story about how people
> will use it, I can think better how to wrap it.
> 
> I.e., does the Cscore function itself create an instance of Csound, or do you
> first create an instance of Csound and then call the CScore functions off
> that?

The cscore() function that the user writes has always essentially been a
callback.  Whether it was compiled into csound or into a standalone cscore
application, main() was always provided by the Csound code and would take
care of setting up the system and opening files, etc. before calling the
user cscore() routine.

With Csound 5, cscore() now takes a CSOUND* argument but that instance is
provided by Csound.  cscore() then can use this pointer to call all of the
Cscore API functions.

This is all still the "traditional" way of using Cscore, and continues to
work with Csound 5.  However, I have also made it possible now to do things
a little bit differently.

A host application can now also create an instance of Csound and prepare it
for Cscore processing by calling csoundInitializeCscore().  Then it can call
any part of the Cscore API and the need to write a cscore() function and
link it to either Csound or a main() stub is no longer there.

So you could do this, for example:

CSOUND*  cs;
int      err;
FILE*    in, out;
EVENT*   e;
EVLIST*  a;

cs = csoundCreate(NULL);

// open input and output scores here

err = csoundInitializeCscore(cs, in, out);
if (err)  return;

// make a score in memory
a = cscoreCreateList(cs, 11);  // 11 event slots

for (int i = 0; i < 10; i++) {
  e = cscoreCreateEvent(cs, 4);  // 4 p-fields
  e->op = 'i';
  e->p[1] = 1;            // instrument 1
  e->p[2] = i * 0.25;     // start every quarter beat
  e->p[3] = 0.10          // 0.10 beats long
  e->p[4] = 64.0 * (i+1)  // play harmonic series on 64Hz
  a = cscoreListAppend(cs, a, e);
}

a = cscoreListAppendStringEvent(cs, a, "e"); // add e-card

cscoreListPut(cs, a);        // write notes to output score
cscoreFreeListEvents(cs, a); // reclaim memory

// close the score files here
// could now call csoundReset(cs) and then use the
// same instance for rendering the score we created


Of course, Cscore is also very good for reading in existing scores and
modifying them.  (In fact, it always requires an input score to run -- maybe
I should find a way to change that).

Anyways, let me know if I can explain this any better.

Anthony Kozar
anthonykozar AT sbcglobal DOT net
http://akozar.spymac.net/



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel





-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2005-10-28 20:04
FromAnthony Kozar
SubjectRe: [Cs-dev] scsort and scxtract
Michael Gogins wrote on 10/28/05 2:38 PM:

> I am only interested in supporting the second mode. Is that OK with you?

That's good.  I don't think that it really makes any sense to try to support
writing a cscore() callback in other languages.

> I agree that the code should be changed to omit the requirement for an input
> score.

OK.  I will look into what needs to be done to accomplish this.

> As you may or may not be aware, CsoundVST contains a CsoundScore class which
> facilities for reading, modifying or creating, and writing orc, sco, and csd
> files. There is obviously some overlap in functionality with CScore.
> CsoundScore works in the following way: the API user programmatically sets
> orchestra text, then programmatically adds score lines to the score, then
> calls CsoundFile::exportForPerformance which writes out an orc and sco file.
> You then call csoundPerform to render the exported files.

I think I was dimly aware of this but I have never looked at the code.  I
expected that there will be some overlap with this and with other libraries
written in scripting languages such as Python.  Some of these facilities
were written before the API existed (like OMDE/pmask).  I wonder if it makes
sense to revise these compositional tools to use the Cscore API since Cscore
is very "low-level" score manipulation but has the advantage of using
Csound's own score-reading code.

> What happens if you call CScore functions while a performance is running?
> CsoundFile does nothing in this case.

Calling Cscore functions from a host during performance will produce
undefined behavior.  Cscore reads directly from the open score file
referenced by Csound's global variable scfp.

Calling Cscore functions during the usual Compile/Perform cycle is possible
if you set a cscore() callback (with csoundSetCscoreCallback()) and specify
the "-C" flag in the arguments to Csound.  The Cscore API may then be used
in the callback.  Event lists can be immediately performed by calling
cscoreListPlay().

However, there are serious limitations presently to this approach due to the
historical way in which this worked.  The cscore() callback is called from
musmon() which is called during csoundCompile().  If you perform the score
at this time using cscoreListPlay() then all performance happens immediately
with no external control.  If the host afterwards calls csoundPerform*(), it
returns immediately saying "score finished."

If you do not call cscoreListPlay() from the callback, put use
cscoreListPut() instead, then I think the modified score gets written back
out to a file, then gets read back in by coundPerform*() and rendered.

Either way, it is not really possible to manipulate a score this way in
real-time.  And using Cscore with real-time events is not possible as far as
I know.

The whole situation with cscoreListPlay() really needs to be rethought and
redesigned.  I just haven't taken the time yet to figure out how this can be
done.

Anthony Kozar
anthonykozar AT sbcglobal DOT net
http://akozar.spymac.net/



-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net