If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
NEW REGISTRATIONS - please contact us if you wish to register on the forum
Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright
RUBY Counter - this was suppose to be easy :|
36 posts
• Page 1 of 4 • 1, 2, 3, 4
RUBY Counter - this was suppose to be easy :|
Yeah ... I thought it'd be easy ... for a little project idea I wanted to do.
I'm trying to make a COUNTER. Was thinking RUBY based.
What I have:
OK ... so it increments 1/sec. [good].
Whenever I start the app, I can only get it to start at ZERO.
That's good, as I do need a way to manually RESET it to ZERO. But I also need it to run from the LAST VALUE,
so that when I re-run the app, it will start at the last elapsed time.
I pulled out ALL of my experimentation from this code [it wasn't pretty ... and it didn't work].
If anyone can guide me, the objective is:
1. A trigger or Boolean to start/stop the counter.
2. internally save the last counter value [do I need to right to a file ??? hope not ... but]
3. start app to count from this 'last saved' value.
4. option to RESET counter to ZERO.
ok ... I'm sure the RUBY GURUS are chuckling about this ... I've been going through a bunch of RUBY sites for
researching this. How I got to the included code. But everything I've tried since as been a mess of errors, not
working, or always starting at zero.
anyway ... appreciate anyone reading through this. Could really use the help.
Thanks GANG.
I'm trying to make a COUNTER. Was thinking RUBY based.
What I have:
- Code: Select all
def init
input 100,nil
end
def event i,v,t
output 0, t
input 100,nil, t+1
end
OK ... so it increments 1/sec. [good].
Whenever I start the app, I can only get it to start at ZERO.
That's good, as I do need a way to manually RESET it to ZERO. But I also need it to run from the LAST VALUE,
so that when I re-run the app, it will start at the last elapsed time.
I pulled out ALL of my experimentation from this code [it wasn't pretty ... and it didn't work].
If anyone can guide me, the objective is:
1. A trigger or Boolean to start/stop the counter.
2. internally save the last counter value [do I need to right to a file ??? hope not ... but]
3. start app to count from this 'last saved' value.
4. option to RESET counter to ZERO.
ok ... I'm sure the RUBY GURUS are chuckling about this ... I've been going through a bunch of RUBY sites for
researching this. How I got to the included code. But everything I've tried since as been a mess of errors, not
working, or always starting at zero.
anyway ... appreciate anyone reading through this. Could really use the help.
Thanks GANG.
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: RUBY Counter - this was suppose to be easy :|
I dont think you can store the last ruby value without the file continuously saving itself? I think the best choice would be to save your value as a text file and read it from there when you open it again?
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: RUBY Counter - this was suppose to be easy :|
Hi RJ
Here's my take on it, I'm sure the more experienced guys can come up with something better!
Hope this helps
Edit - Sorry about the filename, I thought Adam had posted twice
Here's my take on it, I'm sure the more experienced guys can come up with something better!
Hope this helps
Edit - Sorry about the filename, I thought Adam had posted twice
-
DaveyBoy - Posts: 131
- Joined: Wed May 11, 2016 9:18 pm
- Location: Leeds UK
Re: RUBY Counter - this was suppose to be easy :|
Here you go... with added bonus: you can reset the counter to any number (not only zero).
Possible nitpicks:
-when you reset the counter by new value it also resets the trigger timing. That means the time between last 'natural' tick and the one caused by reset may be less than 1 second. You can fix this issue by commenting out the two lines after "@n=v" which reset the trigger.
-stopping the counter and starting it again also resets the trigger timing. You can fix this by rounding up the trigger time (using .ceil method) - replace each "input 99,nil,t" with "input 99,nil,t.ceil".
Problems with your approach was, you output the internal ruby time (the "t" input variable in event also accessible through "time" method), which is used by flowstone to schedule events. You can't stop the timer, nor should you rely on it starting from 0. Honestly, I'm surprised that it does - I expected it to be synced with UNIX time or something similar...
Possible nitpicks:
-when you reset the counter by new value it also resets the trigger timing. That means the time between last 'natural' tick and the one caused by reset may be less than 1 second. You can fix this issue by commenting out the two lines after "@n=v" which reset the trigger.
-stopping the counter and starting it again also resets the trigger timing. You can fix this by rounding up the trigger time (using .ceil method) - replace each "input 99,nil,t" with "input 99,nil,t.ceil".
Problems with your approach was, you output the internal ruby time (the "t" input variable in event also accessible through "time" method), which is used by flowstone to schedule events. You can't stop the timer, nor should you rely on it starting from 0. Honestly, I'm surprised that it does - I expected it to be synced with UNIX time or something similar...
- Attachments
-
- counter.fsm
- (1.3 KiB) Downloaded 928 times
- KG_is_back
- Posts: 1196
- Joined: Tue Oct 22, 2013 5:43 pm
- Location: Slovakia
Re: RUBY Counter - this was suppose to be easy :|
alright yous guys ... I'm studying BOTH your postings to understand how you did this [you're good] !
But I'm reading Adam's post about maintaining last value ... humm need to test this.
But I'm reading Adam's post about maintaining last value ... humm need to test this.
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: RUBY Counter - this was suppose to be easy :|
OK ... first ... THANKS for posting examples !
RUBY has been a challenge for me to grasp. What is interesting is, having tried to work up my own solution ...
and then seeing what you've Guys have created, I would hope to gleen a tad more understanding. THANKS.
KG ... the added comments are a nice bonus !
just an aside ... I've been to so many of the RUBY sites. I've seen so many examples/explanations and code.
So much of what I've tried from there just does NOT work in FS Ruby implementation. Once in awhile, I'm able to
get something working, but its rare ... and so are the huge PARTIES I throw when I do get it working
anyway
One thing I noticed ... this SAVED STATE command. I was hoping this might have been a solution to what Adam
had warned. But that does not seem the case.
If I then need to Save/Load a data file ... then KG may have provided the path for this.
I'd like to hear back [first] on this, before figuring the way forward.
This is a little project idea for a VST plugin to calculate the amount of time spent PLAYING a DAW. It only calcs
the PLAYing time for a specific reason I have for my personal work. I use REAPER for a lot of my work. I have many
on going mastering projects. We already have all the normal clocking available. This was just something specific that got my curiosity. I hope trying to make it happen won't always be such a challenge [but it seems to be for me].
anyway ... wait on replys .... thanks again !
RUBY has been a challenge for me to grasp. What is interesting is, having tried to work up my own solution ...
and then seeing what you've Guys have created, I would hope to gleen a tad more understanding. THANKS.
KG ... the added comments are a nice bonus !
just an aside ... I've been to so many of the RUBY sites. I've seen so many examples/explanations and code.
So much of what I've tried from there just does NOT work in FS Ruby implementation. Once in awhile, I'm able to
get something working, but its rare ... and so are the huge PARTIES I throw when I do get it working
anyway
One thing I noticed ... this SAVED STATE command. I was hoping this might have been a solution to what Adam
had warned. But that does not seem the case.
If I then need to Save/Load a data file ... then KG may have provided the path for this.
I'd like to hear back [first] on this, before figuring the way forward.
This is a little project idea for a VST plugin to calculate the amount of time spent PLAYING a DAW. It only calcs
the PLAYing time for a specific reason I have for my personal work. I use REAPER for a lot of my work. I have many
on going mastering projects. We already have all the normal clocking available. This was just something specific that got my curiosity. I hope trying to make it happen won't always be such a challenge [but it seems to be for me].
anyway ... wait on replys .... thanks again !
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: RUBY Counter - this was suppose to be easy :|
Than a counter may not be the best option if this is the intended usage. A simpler approach would be that you get the time from windows when you open the plugin, and calculate the difference only when you press play in the daw. Then when you press stop, you save that difference in a text file. Then next time you open the vst, it reads the text file and adds it to the windows time for the total amount. At least thats how I would do it
- adamszabo
- Posts: 667
- Joined: Sun Jul 11, 2010 7:21 am
Re: RUBY Counter - this was suppose to be easy :|
Hi Adam.
Yeah. That was my first approach using the TIME/DATE function in RUBY.
I had that working ... minus the SAVEing of the data to a file. But it was getting more complicated.
To me, it seems counting the seconds only when PLAY is active was cleaner. For the display section, I have
the RUBY routine to convert Sec to HH:MM:SS working.
The key issue [as you raised], the need to SAVE data to file and AUTO load it back.
I had HOPE there was a way to store this DATA in the DAW via the PreSet Manager. Much in the way a VST plugin works. That is the format of this little app.
Wish I understood why the Preset manager is not an option
Yeah. That was my first approach using the TIME/DATE function in RUBY.
I had that working ... minus the SAVEing of the data to a file. But it was getting more complicated.
To me, it seems counting the seconds only when PLAY is active was cleaner. For the display section, I have
the RUBY routine to convert Sec to HH:MM:SS working.
The key issue [as you raised], the need to SAVE data to file and AUTO load it back.
I had HOPE there was a way to store this DATA in the DAW via the PreSet Manager. Much in the way a VST plugin works. That is the format of this little app.
Wish I understood why the Preset manager is not an option
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: RUBY Counter - this was suppose to be easy :|
Not everything you said is totally clear to me, but let me say this:
If you're having issues with Ruby examples, it almost always is one of the following.
save state / load state are convenient methods for RubyEdits to maintain their status automatically while working on the schematic. So, when saving the schematic, save state is executed, and when loading a schematic, load state is executed.
It has nothing to do with an exported plugin or app. The only way to save data between sessions of those is to write them to disc. There are prims that notify of closing or loading of the app/plugin. They are called "About To Close" and "After Load". Use their triggers to save/load your data to disc. Ruby offers a vast variety of methods to write to and read from disc. I have posted several examples that automatically read from disc, and I think there was at least one that involved writing to disc.
If you're having issues with Ruby examples, it almost always is one of the following.
- You don't transform the console commands (in Flowstone the RubyEdit acts as a console, the irb does not exist here).
- Just don't use the console commands. If you want to see values, descriptions, classes, methods, and so on, use both, the watch command and the various information commands of all objects. Everything will be "printed" to the info pane, which is the equivalent to the irb console.
- Extensions are not part of Flowstone's Ruby implementation. Basically, if you see in an example code a line with the keyword "require", it is not suited for Flowstone Ruby. At least not on a beginner level.
save state / load state are convenient methods for RubyEdits to maintain their status automatically while working on the schematic. So, when saving the schematic, save state is executed, and when loading a schematic, load state is executed.
It has nothing to do with an exported plugin or app. The only way to save data between sessions of those is to write them to disc. There are prims that notify of closing or loading of the app/plugin. They are called "About To Close" and "After Load". Use their triggers to save/load your data to disc. Ruby offers a vast variety of methods to write to and read from disc. I have posted several examples that automatically read from disc, and I think there was at least one that involved writing to disc.
"There lies the dog buried" (German saying translated literally)
- tulamide
- Posts: 2714
- Joined: Sat Jun 21, 2014 2:48 pm
- Location: Germany
Re: RUBY Counter - this was suppose to be easy :|
If anyone can guide me, the objective is:
1. A trigger or Boolean to start/stop the counter.
2. internally save the last counter value [do I need to right to a file ??? hope not ... but]
3. start app to count from this 'last saved' value.
4. option to RESET counter to ZERO.
Hi RJ,
What you're describing here is a 'Sample and Hold'.
Your zero reset is a valid request, we call it a 'drain', it purges the last sample taken and returns a '0' value to the 'hold' location.
A REALLY elegant solution is to delay your 'stop' command by one clock cycle, use that cycle to activate the 'sample', then 'hold only that sample before you shut down.
That way you're not taking and endless stream of samples, just the one you need.
I hope this helps.
ROXY
1. A trigger or Boolean to start/stop the counter.
2. internally save the last counter value [do I need to right to a file ??? hope not ... but]
3. start app to count from this 'last saved' value.
4. option to RESET counter to ZERO.
Hi RJ,
What you're describing here is a 'Sample and Hold'.
Your zero reset is a valid request, we call it a 'drain', it purges the last sample taken and returns a '0' value to the 'hold' location.
A REALLY elegant solution is to delay your 'stop' command by one clock cycle, use that cycle to activate the 'sample', then 'hold only that sample before you shut down.
That way you're not taking and endless stream of samples, just the one you need.
I hope this helps.
ROXY
-
rocknrollkat - Posts: 213
- Joined: Mon Jan 04, 2016 7:04 pm
- Location: Oakland Gardens, New York City, U.S.A.
36 posts
• Page 1 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 49 guests