Flush post buffer?

View: New views
6 Messages — Rating Filter:   Alert me  

Flush post buffer?

by Nathaniel Virgo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

Is there a way to flush the post buffer?

I have some (non sound-making) code that looks like this:

Routine({
   inf.do {
      // do a few seconds of intensive genetic algorithm stuff, and print out some results
      1.0.wait; // wait for post buffer to flush itself
   }
}).play;

without the 1.0.wait it will beachball forever, not allowing me to interrupt it.  But waiting for 1 second every now and then slows it down and seems like a silly way to do it.  I can reduce the 1.0 but at some un-predictable point it will stop flushing the output and beachball forever. 

Is there a way to force code to flush the post buffer and/or check whether Cmd-. has been pressed?  I noticed there is a method IOStream.flush, but it is empty.

Nathaniel


Re: Flush post buffer?

by nescivi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday 22 July 2008 13:07:58 Nathaniel Virgo wrote:

> Hi
>
> Is there a way to flush the post buffer?
>
> I have some (non sound-making) code that looks like this:
>
> Routine({
>    inf.do {
>       // do a few seconds of intensive genetic algorithm stuff, and print
> out some results
>       1.0.wait; // wait for post buffer to flush itself
>    }
> }).play;
>
> without the 1.0.wait it will beachball forever, not allowing me to
> interrupt it.  But waiting for 1 second every now and then slows it down
> and seems like a silly way to do it.  I can reduce the 1.0 but at some
> un-predictable point it will stop flushing the output and beachball
> forever.
>
> Is there a way to force code to flush the post buffer and/or check whether
> Cmd-. has been pressed?  I noticed there is a method IOStream.flush, but it
> is empty.

On Mac-OSX you can retrieve the postbuffer using Document and set its string
to "".

On Linux, it's a bit more complicated, but you could send a emacs lisp command
to clear the post buffer (look up the function name in one of the el files).

sincerely,
marije

_______________________________________________
sc-users mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Flush post buffer?

by Dan Stowell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Try this:

Routine({
   inf.do {
      // do a few seconds of intensive genetic algorithm stuff, and print
out some results
      0.0.wait; // wait for post buffer to flush itself
   }
}).play;


2008/7/22 Nathaniel Virgo <nathanielvirgo@...>:

> Hi
>
> Is there a way to flush the post buffer?
>
> I have some (non sound-making) code that looks like this:
>
> Routine({
>    inf.do {
>       // do a few seconds of intensive genetic algorithm stuff, and print
> out some results
>       1.0.wait; // wait for post buffer to flush itself
>    }
> }).play;
>
> without the 1.0.wait it will beachball forever, not allowing me to interrupt
> it.  But waiting for 1 second every now and then slows it down and seems
> like a silly way to do it.  I can reduce the 1.0 but at some un-predictable
> point it will stop flushing the output and beachball forever.
>
> Is there a way to force code to flush the post buffer and/or check whether
> Cmd-. has been pressed?  I noticed there is a method IOStream.flush, but it
> is empty.
>
> Nathaniel
>
>



--
http://www.mcld.co.uk

_______________________________________________
sc-users mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

Re: Flush post buffer?

by Nathaniel Virgo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Unfortunately this doesn't work.  Here is a better demonstration of the problem I'm having.

Try

(
10.do {
    2000000.do {};
    "hello".postln;
}
)

This doesn't print out "hello" after each chunk of computation but instead buffers them and prints them all at the end, which isn't what I want.  So I'm doing something more like

(
Routine({
    10.do {
        2000000.do {};
        "hello".postln;
        0.5.wait;
    }
}).play;
)

This does print "hello" after each chunk -- but if I make the 0.5 into 0.1 or 0.0 it stops working again.  Whether it prints them or not seems to depend both on the wait time and on how long the computation takes, so if my computation starts taking longer it can lead to an infinite beachball.

So it seems that flushing (ie. emptying the buffer and printing) the post window is something that happens automatically every now and then, but only when there's nothing much else going on, and I'm looking for a way to force it -- or for some other way to monitor my computations.

Nathaniel



2008/7/22 Dan Stowell <danstowell@...>:
Try this:

Routine({
  inf.do {
     // do a few seconds of intensive genetic algorithm stuff, and print
out some results
     0.0.wait; // wait for post buffer to flush itself
  }
}).play;


2008/7/22 Nathaniel Virgo <nathanielvirgo@...>:
> Hi
>
> Is there a way to flush the post buffer?
>
> I have some (non sound-making) code that looks like this:
>
> Routine({
>    inf.do {
>       // do a few seconds of intensive genetic algorithm stuff, and print
> out some results
>       1.0.wait; // wait for post buffer to flush itself
>    }
> }).play;
>
> without the 1.0.wait it will beachball forever, not allowing me to interrupt
> it.  But waiting for 1 second every now and then slows it down and seems
> like a silly way to do it.  I can reduce the 1.0 but at some un-predictable
> point it will stop flushing the output and beachball forever.
>
> Is there a way to force code to flush the post buffer and/or check whether
> Cmd-. has been pressed?  I noticed there is a method IOStream.flush, but it
> is empty.
>
> Nathaniel
>
>



--
http://www.mcld.co.uk

_______________________________________________
sc-users mailing list

info (subscribe and unsubscribe): http://swiki.hfbk-hamburg.de:8888/MusicTechnology/880
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/


Re: Flush post buffer?

by James Harkins-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The problem is that your routine is playing on TempoClock, which schedules according to logical time in order to keep musical timing precise. That is, however much time you wait is added to the clock's logical time at the time it woke up. If the wait time is shorter than the time you're processing takes, it's the same as not having any weight statement at all.

But, if you use AppClock, then the wait time is measured from the end of processing --

AppClock.sched(0, r {
Main.elapsedTime.postln;
2000000.do { nil };
Main.elapsedTime.postln;
0.01.wait;
Main.elapsedTime.postln;
2000000.do { nil };
Main.elapsedTime.postln;
});

75.577352774
75.943286465
75.955738997
76.319474124

This shows that the empty do loop takes roughly 0.37 seconds, and the delta between the middle two numbers (corresponding to 0.01.wait) is within a couple of milliseconds of 0.01 seconds. 0.01 is measured from the *end* of processing.

By contrast, if you used SystemClock or TempoClock.default instead, the do would still run for 0.3x seconds, but the wake-up time would be exactly 75.577... + 0.01, which time has already passed. So the routine will wake up again immediately and (since these are higher priority clocks) the routine waking up takes precedence over printing output.

Use AppClock for this.
hjh


: H. James Harkins

: jamshark70@...

: http://www.dewdrop-world.net

.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman



Re: Flush post buffer?

by Nathaniel Virgo-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Great, thanks James for the explanation and the solution.

Nathaniel


2008/7/23 James Harkins <jamshark70@...>:
The problem is that your routine is playing on TempoClock, which schedules according to logical time in order to keep musical timing precise. That is, however much time you wait is added to the clock's logical time at the time it woke up. If the wait time is shorter than the time you're processing takes, it's the same as not having any weight statement at all.

But, if you use AppClock, then the wait time is measured from the end of processing --

AppClock.sched(0, r {
Main.elapsedTime.postln;
2000000.do { nil };
Main.elapsedTime.postln;
0.01.wait;
Main.elapsedTime.postln;
2000000.do { nil };
Main.elapsedTime.postln;
});

75.577352774
75.943286465
75.955738997
76.319474124

This shows that the empty do loop takes roughly 0.37 seconds, and the delta between the middle two numbers (corresponding to 0.01.wait) is within a couple of milliseconds of 0.01 seconds. 0.01 is measured from the *end* of processing.

By contrast, if you used SystemClock or TempoClock.default instead, the do would still run for 0.3x seconds, but the wake-up time would be exactly 75.577... + 0.01, which time has already passed. So the routine will wake up again immediately and (since these are higher priority clocks) the routine waking up takes precedence over printing output.

Use AppClock for this.
hjh


: H. James Harkins

: jamshark70@...

: http://www.dewdrop-world.net

.::!:.:.......:.::........:..!.::.::...:..:...:.:.:.:..:


"Come said the Muse,

Sing me a song no poet has yet chanted,

Sing me the universal."  -- Whitman