Beats per minute

Discussion in 'Questions (Windows Mobile)' started by Cor, Feb 1, 2008.

  1. Cor

    Cor Active Member Licensed User

    BPM calculator (beats perminute)

    Calculate the the BPM when tapping on e.g. a label of the form

    Is it possible to convert following javascript code to basci4ppc

    Hints are welcome

    grCor


    function TapForBPM(e)
    {
    document.BEATSPERMINUTE.WAIT.blur();
    timeSeconds = new Date;
    secs = timeSeconds.getTime();
    if ((secs - secsPrevious) > 1000 * document.BEATSPERMINUTE.WAIT.value)
    {
    count = 0;
    }

    if (count == 0)
    {
    document.BEATSPERMINUTE.AVG.value = "";
    document.BEATSPERMINUTE.TAP.value = "First Beat";
    secsFirst = secs;
    count = 1;
    }
    else
    {
    bpmAvg = 60000 * count / (secs - secsFirst);
    document.BEATSPERMINUTE.AVG.value = (Math.round(bpmAvg * 100)) / 100;
    count++;
    document.BEATSPERMINUTE.TAP.value = count;
    }
    secsPrevious = secs;
    return true;
    }
     
  2. Rioven

    Rioven Active Member Licensed User

    Tap on button per minute

    Hi,
    Hope this code helps a bit...

    Code:
    Sub Globals
    secSecond=
    0
    secFirst=
    0
    End Sub
    Sub App_Start
       Form1.Show
    End Sub

    Sub button1_click
       secSecond=Now
          
    If secFirst=0 Then 
             secFirst = Now
             label1.text=
    "start"
             label2.text=
    "start"
          
    End If
       r=secSecond-secFirst
          
    If r>0 Then 
             label1.text=
    Round(r/ctickspersecond,2)
             bpmAvg = 
    Round(60/(r/ctickspersecond),0)
             label2.text=bpmAvg
          
    End If
       secFirst=secSecond
    End Sub

    also
    attached sbp file.

    Regards,
    Rioven
     

    Attached Files:

    • bpm.sbp
      File size:
      998 bytes
      Views:
      35
  3. Cor

    Cor Active Member Licensed User

    works great,

    thanks

    will improve my learning curve in basic4ppc ;)

    grCor
     
  4. Cor

    Cor Active Member Licensed User

    When running on rx 3715 pda

    bpm is result is always 30 or 60

    seems that it cannot handle this on a pda

    strange

    who can help

    grCor
     
  5. Cableguy

    Cableguy Expert Licensed User

    It may be because of the use of a button control...
    remove the button and use the code in the form _click event...
    Buttons seem to have some kind of latency time...perhaps to avoid double clikcs when only one was meant...
     
  6. Rioven

    Rioven Active Member Licensed User

    Now value on PPC

    Hi Cor/Cableguy,
    I have tried the code on my device and same result what cor is getting...
    I've found out that the 'Now' ticks returns on device like 633375480580000000 means no milliseconds unlike on desktop. Why??

    Regards,
    Rioven
     
  7. agraham

    agraham Expert Licensed User

  8. Cor

    Cor Active Member Licensed User

    But what is the solution?

    grCor
     
  9. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I guess that the only solution is to use your own timer.
    Then if it is improtant that it stays in sync with the system time you may need to compare your time with the system time and adjust as necessary.

    Regards,
    RandomCoder
     
  10. Rioven

    Rioven Active Member Licensed User

    Using timer

    Hi Cor,
    here is the code...

    Code:
    Sub Globals
    n=
    0
    End Sub

    Sub App_Start
     Form1.show
    timer1.Enabled=
    true
    timer1.Interval=
    1
    End Sub

    Sub Timer1_Tick
    n=n+
    1
    label1.Text=n/
    200
    End Sub

    Sub Button1_Click
    label2.Text=
    Round(n/200,2)
    label3.Text=
    Round(60/(n/200),0)
    n=
    0
    End Sub
    EDIT: CODE is for device, use n/100 on desktop, also finetune as Randomcoder's advice.

    also attached sbp
     

    Attached Files:

    • bpm2.sbp
      File size:
      854 bytes
      Views:
      26
    Last edited: Feb 2, 2008
  11. Erel

    Erel Administrator Staff Member Licensed User

    You should set a larger interval.
    1 ms may not be enough.
     
  12. alfcen

    alfcen Well-Known Member Licensed User

    Hello Cor
    If precision is crucial please consider using dzt's dzHW.dll.
    In there you will find a GetTickCount method.
    Cheers
    Robert
     
  13. Rioven

    Rioven Active Member Licensed User

    dzHW.dll is the answer then...

    Hi Alfcen,
    Thanks for pointing dzt's dzWH.dll. Problem solved!

    Hi Cor, we could use the first code and change 'Now' with 'GetTickCount' and divide by 1000 for seconds lapses per beat.

    Code:
    Sub Globals
    secSecond=
    0
    secFirst=
    0
    End Sub
    Sub App_Start
       Form1.Show
       dzH.New1 
    'dzHW.dll object
    End Sub

    Sub button1_click
       secSecond=dzh.GetTickCount
          
    If secFirst=0 Then 
             secFirst = dzh.GetTickCount
             label1.text=
    "start"
             label2.text=
    "start"
          
    End If
       rt=secSecond-secFirst
          
    If rt>0 Then 
             label1.text=
    Round(rt/1000,2)
             bpmAvg = 
    Round(60/(rt/1000),0)
             label2.text=bpmAvg
          
    End If
       secFirst=secSecond
    End Sub
    Thanks guys for the refreshers!:)

    Regards,
     
  14. Cor

    Cor Active Member Licensed User

    Thanks,

    where could i download that dll?

    grCor
     
  15. Rioven

    Rioven Active Member Licensed User

  16. Cor

    Cor Active Member Licensed User

    Thanks for all the help
    will try this evening on pda

    Can Gettickcount be implemented directly as default in basic4ppc
    because it will be used a lot i think.

    grCor
     
  17. Cor

    Cor Active Member Licensed User

    Yeah, its working on the PDA

    Thanks
     
Loading...