Csound Csound-dev Csound-tekno Search About

[Csnd] readk question..

Date2008-02-27 11:48
FromRory Walsh
Subject[Csnd] readk question..
The following instrument and UDO write data to a text file and then 
after 5 seconds should read the data back. The thing is the instrument 
simply stops after 5 seconds. I'm pretty sure that the file is not being 
released after dumpk writes to it and as a result readk fails. If there 
any way around this? I want to periodically write and read control data 
during an instruments performance, can this be done using readk and dump k?

Rory.





-odevaudio -b10 -idevaudio


sr = 44100
ksmps = 4410
nchnls = 1

opcode dataRW, k, Ski
Sname, kvalue, iRW   xin
kout init 0
        if (iRW==0) then
               dumpk  kvalue, Sname, 8, 0
               kout = kvalue
        else
               kres readk Sname, 8, 0
               kout = kres
        endif
        xout kout
endop

instr 1
kline line 0, p3, p3
if(kline < 5) then
printks "writing", 0
k1 dataRW "test.txt", kline, 0
elseif(kline > 5) then
printks "reading", 0
k1 dataRW "test.txt", kline, 1
endif

printk2 k1
endin



f1 0 1024 10 1
i1 0 15



Date2008-02-27 17:34
From"Steven Yi"
Subject[Csnd] Re: readk question..
AttachmentsNone  

Date2008-02-27 18:03
FromRory Walsh
Subject[Csnd] Re: Re: readk question..
I have a GUI front end that will write to a file when a user hits a 
button. Then when the user hits that button again it stops writing and 
reads it back. The problem is that the program will crash if I don't 
stop reading before the file ends. When I try to simplifier my other 
code I can't seem to get readk and dumpk to access the same file at all 
without a crash. I can't see why one works, to a point, and the simpler 
one doesn't. I need to do some more messing around it it. I can ask John 
in person at the LAC, I think he wrote the opcode to begin with.

Rory.



Steven Yi wrote:
> Hi Rory,
> 
> I took a very quick look and the code is in OOps/dumpf.c.  All of the
> file code looks like it is opening with "rb" or "wb" depending on
> reading or writing.  I don't know c file handling very well, but
> looking at manuals I wonder if using r+b and w+b might be a possible
> solution? Otherwise though, it seems using files for this kind of
> thing could be sort of tricky.
> 
> steven
> 
> On Wed, Feb 27, 2008 at 3:48 AM, Rory Walsh  wrote:
>> The following instrument and UDO write data to a text file and then
>>  after 5 seconds should read the data back. The thing is the instrument
>>  simply stops after 5 seconds. I'm pretty sure that the file is not being
>>  released after dumpk writes to it and as a result readk fails. If there
>>  any way around this? I want to periodically write and read control data
>>  during an instruments performance, can this be done using readk and dump k?
>>
>>  Rory.
>>
>>
>>
>>  
>>  
>>  -odevaudio -b10 -idevaudio
>>  
>>  
>>  sr = 44100
>>  ksmps = 4410
>>  nchnls = 1
>>
>>  opcode dataRW, k, Ski
>>  Sname, kvalue, iRW   xin
>>  kout init 0
>>         if (iRW==0) then
>>                dumpk  kvalue, Sname, 8, 0
>>                kout = kvalue
>>         else
>>                kres readk Sname, 8, 0
>>                kout = kres
>>         endif
>>         xout kout
>>  endop
>>
>>  instr 1
>>  kline line 0, p3, p3
>>  if(kline < 5) then
>>  printks "writing", 0
>>  k1 dataRW "test.txt", kline, 0
>>  elseif(kline > 5) then
>>  printks "reading", 0
>>  k1 dataRW "test.txt", kline, 1
>>  endif
>>
>>  printk2 k1
>>  endin
>>
>>  
>>  
>>  f1 0 1024 10 1
>>  i1 0 15
>>  
>>  
>>
>>
>>  Send bugs reports to this list.
>>  To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>>
> 
> 
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 

Date2008-02-27 18:16
FromAnthony Kozar
Subject[Csnd] Re: Re: Re: readk question..
I would try putting the dumpk and readk in separate instruments and only
running each when writing or reading respectively.  Csound does not close
the file until the instrument is deactivated.

Anthony Kozar
mailing-lists-1001 AT anthonykozar DOT net
http://anthonykozar.net/

Rory Walsh wrote on 2/27/08 1:03 PM:

> I have a GUI front end that will write to a file when a user hits a
> button. Then when the user hits that button again it stops writing and
> reads it back. The problem is that the program will crash if I don't
> stop reading before the file ends. When I try to simplifier my other
> code I can't seem to get readk and dumpk to access the same file at all
> without a crash. I can't see why one works, to a point, and the simpler
> one doesn't. I need to do some more messing around it it. I can ask John
> in person at the LAC, I think he wrote the opcode to begin with.

> Steven Yi wrote:

>> I took a very quick look and the code is in OOps/dumpf.c.  All of the
>> file code looks like it is opening with "rb" or "wb" depending on
>> reading or writing.  I don't know c file handling very well, but
>> looking at manuals I wonder if using r+b and w+b might be a possible
>> solution? Otherwise though, it seems using files for this kind of
>> thing could be sort of tricky.

>> On Wed, Feb 27, 2008 at 3:48 AM, Rory Walsh  wrote:
>>> The following instrument and UDO write data to a text file and then
>>> after 5 seconds should read the data back. The thing is the instrument
>>> simply stops after 5 seconds. I'm pretty sure that the file is not being
>>> released after dumpk writes to it and as a result readk fails. If there
>>> any way around this? I want to periodically write and read control data
>>> during an instruments performance, can this be done using readk and dump k?


Date2008-02-27 18:36
FromRory Walsh
Subject[Csnd] Re: Re: Re: Re: readk question..
I was thinking that myself, I'm going to try it with fiopen, ficlose and 
foutk now. Out of curiosity the following instrument will write and then 
read from a file without problem, until it gets to the end of the file 
it's reading. Unlike my previous instrument this one uses fprintks.



-odevaudio -b10 -idevaudio


sr = 44100
ksmps = 64
nchnls = 1

opcode dataRW, k, Ski
Sname, kvalue, iRW   xin
kout init 0
        if (iRW==0) then
               fprintks Sname, "%2.1f\n", kvalue
               kout = kvalue
        else
               kres readk Sname, 8, 0
               kout = kres
        endif
        xout kout
endop

;----------------- write and read data to text file ------------
instr 1
kline init 0
kline line 0, p3, p3
k1 init 0
if(kline < 5) then
	k1 dataRW "test1.txt", kline, 0
	printks "writing: %f\n", 0, k1
elseif(kline > 7) then
	k1 dataRW "test1.txt", 1, 1
	printks "reading: %f\n", 0, k1
endif
endin



f1 0 1024 10 1
i1 0 25





Anthony Kozar wrote:
> I would try putting the dumpk and readk in separate instruments and only
> running each when writing or reading respectively.  Csound does not close
> the file until the instrument is deactivated.
> 
> Anthony Kozar
> mailing-lists-1001 AT anthonykozar DOT net
> http://anthonykozar.net/
> 
> Rory Walsh wrote on 2/27/08 1:03 PM:
>