Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:05:44+00:00 2026-06-12T05:05:44+00:00

The task is to emulate the MIDI player work in js, but just for

  • 0

The task is to emulate the MIDI player work in js, but just for emulate delays between beats. There is an array with beat starting times in beat clock format, for example [960, 1280, 2200, …], and the formula I’m using for calculate millisecond time for each beat tick:

var beatTickTime = 60000 / (tempo * 96);

The problem is in very slow tick real time generation. Even if I use 1 second delay, it is still very slow. Here is how it was implemented:

var tickTimer = setInterval(function() {
     ...
     tickCount += 1; 
}, beatTickTime); // or just 1 ms

Should I pass some beat ticks doing tickCount += someNumber? Or there is more common way to solve this problem? Also I’m not sure about 96 (PPQ * 4 time) in my formula.

P. S. beat ticks comes from parsed guitar pro file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:05:45+00:00Added an answer on June 12, 2026 at 5:05 am

    There’s no guarantee that setInterval() will run as fast as you ask it to. Even if the timeout is set to 1, you can’t count on the function being called 1,000 times each second.

    You’ll most likely need to do something like the following:

    var startTime = (new Date()).getTime();
    setInterval(function() {
      var relTime = (new Date()).getTime() - startTime;
      // relTime is now the number of ms since the script started
    
      /*
      In here, you'll need to see if relTime is large enough to indicate the next
      beat has been reached. So that means keeping some sort of external marker
      to indicate the most recent beat that has occurred -- when relTime is big
      enough to move that marker to the next beat, also run any code that is
      necessary to handle that beat.
      */
    }, 1);
    

    The loop runs “as fast as it can” but still much more slowly than desired. It measures the current time relative to the start of the script, and determines the difference at each iteration. You could divide that time by the tempo of the song, and you’ll have an indicator of where in the song you currently are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I need to emulate a task pane by floating a modeless form over
This task was actually given to us as homework, but the requirement in the
The following code does not work correctly on Windows (but does on Linux): sock
Task: I have an array of records in filtered_records , with the number of
Task: Make text box 100% width but allow enough room for button. Problem: Button
Task is: There are 2 arrays A (numeric floating type) and B is a
Is there a way to emulate the unix cut command on windows XP, without
Task: implement paging of database records suitable for different RDBMS. Method should work for
The task is simple, and the answers might be many. But here goes: On
TASK DETAILS: There is gallery on page, all images previews are loaded on page.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.