set timer between messages within a loop #285
-
Hi everybody, I struggle to have a timer running properly in a loop. For a "bulk memory" request I need to set a 200ms interval between sent messages.
so let's have a loop to send the 100 requests without delay between messages:
Now I need to set an interval of time of at least 200ms between requests:
My timerCallback function is :
This should set an delay of 200ms between each iteration of the loop but I have still the 100 messages sent straight away then the delay occures. Do you know how I can manage to have this working? Thanks a lot in advance for your help. This timer function is a bit tricky sometimes. Damien |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 10 replies
-
Hi Damien, A timer is itself a loop running continuously at a certain timing until you stop it. From my ever expanding never published Step by Step guide 2.x (will further work on it during summer so I can publish it): The philosophy of a timer is that it loops by executing its code at a specific time interval until it is stopped. Some properties:
So:
I didn't verify the code above but you should get the philosophy. |
Beta Was this translation helpful? Give feedback.
-
This is a great explanation ! Every time I have to do a timer I have to think about the logic so this really helps. |
Beta Was this translation helpful? Give feedback.
-
Case: In a CustomComponent, the UiCustomDoubleClickCallback always fires a customMouseDownCallback as well. But because of some weird obscure reason the second mouse down seems to trigger "after" the double click. If double clickitty click: I use a function to paint something with a single click. Want to delete it with a double click. Guess you can figure out what happens. Going over the Juce forums, this seems to be the order for the mouse clicks. Jules advises using "getNumberOfClicks" or to use a timer. -- getNumberOfClicks() -- just counts the amount of clicks. Even a click after a minute still adds up. So not usable right away. So the question is: How do I count the number of clicks in a set period of milliseconds? |
Beta Was this translation helpful? Give feedback.
-
No idea about this! Have you checked all the possible JUCE mouse methods?
Sure you have and maybe not all functionality is available in Ctrlr.
https://stackoverflow.com/questions/5965197/intercepting-mouse-events-on-filebrowsercomponent-in-juce-library
You would know way more than me about such things.
Actually for my Rev 500 panel - do you know how to change the font family
inside a uiComponent - I want to use digital-7.
Also as far as I can tell there is no information about the data in the
manual - it just says 66 total bytes etc, but no assignations so I might
have to go through and do byte changes comparisons by changing each value
on the unit. That could be very tedious. Or just ignore all that and write
a JSON file saving thing that can be saved or loaded and then transmitted.
Each control is using CC but they have this interpolate thing which I
encountered in the C-PLG-150AN where a button 0-127 has 200 values, or was
it the other way round. Other buttons are the same - for example PRE-DELAY
seems to have 200 values on the machine but CC is only 0-127 according to
the manual.
You can see it on the EFF LEVEL bar 0-127 goes from 0-20 bars
This is the function
function interpolate(oldValue)
--The PLG-150 AN editor somehow divides 200 values between 128 sysex
messages
local new_value=0
local old_value=oldValue
local old_min=0
local old_max=127
local new_min=0
local new_max=20
new_value=((old_value-old_min)/(old_max-old_min))*(new_max-new_min)+
new_min
return math.ceil(new_value)
end --end function
---------------------------------------------------------
Attached is far from working panel.
I got part way through working on a JSON file that I didn't post on the
forums, but I notice the subject has come up on the forum again. I had it
partly working well but not perfectly. Has a lot of potential. Like I said
in that post I have just written lua tables to text files - that works very
well too.
…On Sun, May 16, 2021 at 6:39 PM DnaldeT ***@***.***> wrote:
Case: In a CustomComponent, the UiCustomDoubleClickCallback always fires a
customMouseDownCallback as well. But because of some weird obscure reason
the second mouse down seems to trigger "after" the double click.
If double clickitty click:
-- triggers single click
-- triggers double click
-- triggers single click again.
I use a function to paint something with a single click. Want to delete it
with a double click. Guess you can figure out what happens. Going over the
Juce forums, this seems to be the order for the mouse clicks. Jules advises
using "getNumberOfClicks" or to use a timer.
-- getNumberOfClicks() -- just counts the amount of clicks. Even a click
after a minute still adds up. So not usable right away.
-- timer -- Although Goodweather provided a good explanation a few posts
ago, I'm still struggling with it. If I put a timer in a mouseDownCallback,
the timer resets every time the button is pressed.
So the question is: How do I count the number of clicks in a set period of
milliseconds?
-- mouseDown --> wait or set timer for 20 ms and see if another click
happens --> outcome should be 0 (single click) or > 0 (double click)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#285 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASKFXQ54REDLJJIAFTYPBVDTN6HGHANCNFSM44IDZN2A>
.
|
Beta Was this translation helpful? Give feedback.
-
Excellent! Thanks for that. I’ll try it out.
…On Sun, May 16, 2021 at 20:12 DnaldeT ***@***.***> wrote:
Import a font that you want to use to your resources or find the path
where the font is located. Loads of free fonts on the internet that are
close to that digital-7 font, so I guess that just importing from resources
is the easy way to do it. Add the following lines to your paint function of
a custom component:
newFont = resources:getResourceAsFont("getdigital")
g:setFont(newFont)
g:setFont(10.0)
getdigital = the name of the font without the extension.
If you want to add it to a non-custom component you probably have to
override L&F.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#285 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASKFXQYNJZEUPZC4SBSTKGDTN6SARANCNFSM44IDZN2A>
.
|
Beta Was this translation helpful? Give feedback.
-
I wrote a Class Interpolate that converts values 0-127 on a uiSlider to the interpolated value. For example, you send 0-127 to (in my case the Yamaha REV500) but the display on the REV 500 might show as much as 200 values. This class updates uiLabel in a layer sitting above uiSlider to reflect the interpolated value. This is just a rough template and would need to be adapted to a real world situation. The range to interpolate is listed in modulatorCustomIndex as a comma delimited pair of values i.e. 0,200 will interpolate CC 0-127 into 200 values to display on the panel.
|
Beta Was this translation helpful? Give feedback.
Hi Damien,
thx for this question that allows me to explain you what a timer is and how it is working ;-)
I think I already did that in the old forum but it is good to repeat.
A timer is itself a loop running continuously at a certain timing until you stop it.
So, you don't need to have your 1-100 for loop there and starting/stopping the same timer ID 2 100 times.
From my ever expanding never published Step by Step guide 2.x (will further work on it during summer so I can publish it):
The philosophy of a timer is that it loops by executing its code at a specific time interval until it is stopped.
Juce documentation: ((https://www.juce.com/doc/classTimer#details ))
Some properties: