Cabbage Logo
Back to Cabbage Site

Problem with printks and tabs

To see this in action:
I have added these two lines to instr 10 of the Midi_Note_Recorder
Cabbage csd by Ian M.

printks “i %2.0f\t%15.6f\t%15.6f\t%d\t%d\n”, .5, 11, iStart, kDur, iNote, iVel
fprintks “scor.orc”, “i %2.0f\t%15.6f\t%15.6f\t%d\t%d\n”, 11, iStart, kDur, iNote, iVel

The fprintks only writes the last played notes, it does not append…(This is a Csound problem under OS X)

The result of printks is also unexpected, it appends the 2 integers to the floating point in the Cabbage output window:

i 11 2.368435 0.2323813668 ; Should be " 36 68"

Richard

Thanks Richard. I’ll take a look at this once I return from my festive break!

Hi Richard, sorry I’m just seeing this now. Yes printks seems to have some parsing issues. I think decimal points within the string can upset the rest of the string. In this case, you need to insert spaces instead of the tabs that aren’t being read properly. Sorry, not a solution, just a workaround.
fprintks doesn’t seem to append properly if the file is opened and ciosed, as is happening here. If it is just a single instance of the opcode running continuously it should work. However, if you simply want to write played notes to a score file I would use fprints instead. So in instr 10 you could put:

if release:k()==1 then
 event "i", 11, 0, 0, iStart, kDur, iNote, iVel
endif

and instr 11 would look like:

instr 11
 fprints "scor.orc", "i %2.0f\t%15.6f\t%15.6f\t%d\t%d\n", p1, p4, p5, p6, p7
endin 

Note that in order for the start times to be produced in this instrument, the record button must first be clicked.

Thanks Ian, that worked.
I already made a Pythonic version of append to file, but due to some python conflict I could not start that csd with csoundSession (and I do need multithreading in my GUI app…)

pyinit

pyruni {{
def append(inst, st, dur,note, vel):
…with open(‘score11.sco’, ‘a’) as file:
…file.write(‘i %s %s %s %s %s;’ % (inst, st, dur, note, vel))
}}

and then I would call it:
pycall “append”, 11, istrt, kdur, inote, ivel