Beat/time counter
-
Hi everyone. I am trying to make a time counter (like a visual metronome) but I cannot get it running immediately when I click a button, but in the timer.startTimer(50) delay.
Any help/ideas?HiseSnippet 1181.3ocsV8taaaCDmJIJHVacXEnO.b9SNHYN1qcsAaKndwwdHXMIF0cAa6KAzRzVbQhTPhtodEAXO.6AYOd6MX6NRIKYW2rDCL8ACe79C+c+i2MHU4yyxToDmZuYVBm37otCmI0gcCYBI4zSHNehaDO3JsHlmRNdVBKKiGPbb17GPAbpsEw782u7XVDS5yKOhPtTI74uRDKzkmNnyOJhh5yB3uALY44Oqyo9JYWUjZJ.lMcaQRX9WylvOmghsgKwY6dABsJcnlo4YfLGqBlMLTcizJ+khLwnHNRzlLDLj8XR2PQTvfBGMiPb1ZPoauo0seh6Yh.w7yKc+O2vfVpQ0XfyF2EjZ+.fjSEHskERO1cnepHQWxwlNNUp4oiYPntJTrxR13ubc6p.Ij5lwrq48SAh4Zz34sZsOE9Y2u0y6fCnuhMhGQuQnCoxowi3oYdPRHSSeKK0xrM8HZg8lv0cUwIJIPzntkc8bKcBerPxoLTSAC7YpVQyfPC7mPN0WMEw.vMZJ2CsdwIGQaYsP2TNDDAKXJ0npQ+F2WaD0dvQzdxIvczz2HHV8jdgQnFHFLlfEEMBpZniUovkyR0GjoSUIzQS0ZkzSHiPPNdpzWKTRpRdrgQazCSUQM7Kbu8sHcWu26USLl13Krjz26Qq7Y.VSvKSLnAwQU1fUyTQ7lIoBLfYjAiIII7f5KI6BgihCukxix3ejKE7N6s9TLcRA2Gp6rQcfkIpaCbh3Xdf.BYQyd48Aef1Khua87tEhvqtLHOBVe2lY34l3XQdnwxAXShByT8KRA.dERHiFCFqZkh27jzb1csbZTjEVB94r+FZc5dEVI2IrkpH.aTWyemt99KIPN0d6A3CowZoPNTHA49pkugrLJT84GxCnGZjDKNJ39cGQOrZIBXkgKkKXSf2ULkm3YR.Kk9m2cmg8VYEwpCBkfrI80bikDxIMa1zztVAe.S9BwcLgzxakUkOT+BTjgYv6ke4cqotXXAZl2IWTFTXaiQ7xME2Zn40aKWq.VuRy94JM+BYCSSMbezkYMd7J4kW6Fgkdqfcdq+GWwF1mVq9jBJH7N+hCO199M7v21FVQPk7ToPeQBOmtuJJ.GJf++CG0Px6iwgN4HDDUaF47Y4ibrcsDAXjZt4svDC7qNdm7SmdBSyJLDXS3dR3PsF5NNmveKL92NKql6I7rqgm9fI4ye7.h.2iq8cUuxYKb+UrzNVK8nbKY53MFZGWa2eU67KcJsyebYmaDA5PhiqyuBzgbwjPMR8m.E9ZAH51ajeiiA+bn32qDFtrC4CGcCKMnBlFwzKtIAtxTNCnBYgw23HZYlPOq5JUOf0KZcmqWbeg3icGHz9gqFiarBLB49+OvX9RYOxs23wv.9R.tka+edc2.6+35esZJ9H4YLcp.pUbOeZ7PXWTeNb6RI7rKVSf0A4zsPZLBLjKCLD+C7kyrMR6jyrcASRLyOUckusqCW6aGyI.ljlsbq4dFRSm2r451pYKRLrA5U99n6+kPK8p04qVCcd5ZnyyVCc950PmmuF57h0PmCuScvk++9oZUrsc.NXPOyidNN8j3dtlpPx+BLNp1xJ```
-
A couple of things here a off.
So first of all you do not need to start a timer again inside the timer callback. If you call startTimer(300) it starts running until you hit stopTimer();
To increment immediately simply call incrementCounter()
You had a small bug where you draw the label and then increment the counter. So it's always one behind as well.I've cleaned up your example and optimised it. Take a look
HiseSnippet 1201.3ocsW0saaaCElJIpHVacXEXO.b9JGj.Gms9SvFxpWbRFBVShQcWv1UAzRGawEIRAI5j5UDf9.sGt8FrcHojEsiyVfwpunnjme3G+NeGcX5mKCghBYNwqw6llADuO2evTgJtWLiKHmdDw6y7SfnqT7THmb3zLVQADQ77V+mzN30XCh42e85CYILQHTuEgbojGBugmxU061u6OySRNgEAuCSY89Ou6ogRQOYhbBBl086PxXgWyFCmyztslOw6IGGwUx7AJlBJHdabnLZ5fX4sBq+WxK3CS.8h8HCvDY29DYRjFw5cI8h4IQ8qtzEDLK8qof0sTvW4eFOhOa+Zp3KMFn0Q3xG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4SRGfuKMDvSWHv4q3ddqoUe10czq0Lv.PDYV723uRi6oW6UZbuJijTVXt7pPa2m9YeaZ1Awjv7h2F9moWSWRSWJ9JzqBCmOU2KvuYUC7aW0.e9pF3KV0.e4pF3qV0.2++NP8ejvONQISssMDxY8O17QROuiE52CaTqj+Af6rypB
-
@oskarsh If you are looking for even more immediate feedback use a panel instead of a button. The button will only trigger on the mouse up event but by using a panel you can register a click down event which feels more snappy.
-
@oskarsh thanks mate!!! working like a charm! The panel idea is great also. Thanks for your help :)