Home   Archive   Permalink

R2/View and a running process (another project for fun)

I found out how to grab a string containing a playing song from one of my favourite webradio stations, and I like to turn these into a playlist of played songs. I quickly stuck some program together and I am done. I let my program poll every 60 seconds for a new title. Now I like to make a View version where I have a Start button to start and Stop this process. How can I best do this?

posted by:   iArnold     16-Oct-2015/15:22:45-7:00

One way is to use view/new and a forever loop. Put the activity you want periodically evaluated in the forever loop. Use 'wait to rest any specified period of time, and use a flag variable to determine whether or not any specific activity should occur (here, that variable is 'go). This works because the do-events loop never starts when using view/new:
R E B O L [title: "Multitasking 1"]
go: 1
gui: view/new layout [
     t: text form now/time
     btn "Stop" [go: 0]
     btn "Start" [go: 1]
forever [
     if go = 1 [t/text: form now/time show gui]
     wait .01
Another way is to assign a 'feel to any widget (could be a sensor, or any widget hidden off screen). Change the rate to 0 (or some other period) to start the activity, and 'none to stop the activity:
R E B O L [title: "Multitasking 2"]
view layout [
     t: text form now/time rate 0 feel [
         engage: func [f a e] [
             if a = 'time [
                 t/text: form now/time show t
     btn "Stop" [t/rate: none]
     btn "Start" [t/rate: 0 t/text: form now/time show t]

posted by:   Nick     16-Oct-2015/23:59:41-7:00

Search http://re-bol.com/short_rebol_examples.r for "forever" and "rate" to see a number of each technique in use.

posted by:   Nick     17-Oct-2015/0:04:47-7:00

Thank you Nick! Will send you a playlist soon ;-)

posted by:   iArnold     18-Oct-2015/13:55:39-7:00