GithubHelp home page GithubHelp logo

njmyers / react-metronome Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 2.72 MB

A metronome made for the purposes of learning the React framework and also for making a highly exact and configurable metronome!

Home Page: https://react-metronome.netlify.com/

HTML 6.29% CSS 15.72% JavaScript 77.99%

react-metronome's Introduction

Metronome

Inspiration

For a long time I've been frustrated by digital metronomes. They are usually quite imprecise timekeepers when compared with the regularity of a nice quartz crystal. They also lack the charm associated with an old school wind-up version. This project is an attempt to bridge the gap and give the digital metronome some of the qualities of their real-world equivalents.

Technical Explanantion

Loops

Upon investigation into the timekeeping of metronomes, I found that most metronomes are using some derivative of the javascript method setInterval, or setTimeout. They are also using in a quite simplistic way and are not accounting for the fact that setInterval does not really keep time. The only thing setInterval does is delay execution of code. It is imperative when designing a timekeeper in javascript that we use a method which actually will keep the time for us. The method that I have chosen to keep time in this project is the performance object. This will give us a higher resolution of timekeeping (depending on browser security settings) when compared with the Date.now() method or even worse a simple setInterval.

Using the performance timestamp we can store references to the time at the last interval of code execution. When a new interval of code execution happens we can then calculate the precise amount of time that has passed and avoid any sort of time synchronization that comes from the date object. After calculation we can add the precise amount of time from our interval to the previous tally of time and determine with greater accuracy when our specific metronome beat should occur.

Audio Scheduling

And now for the next part! We have to schedule our audio. We cannot rely on our next interval in order to schedule the click of our audio. Even though we know precisely what time it is, if we call setTimeout again we have no idea of knowing when our next code execution will happen. For our browser and desktop versions we can now use the awesome Web Audio API. Reading through the API specification you can be sure it was designed with professional audio applications in mind. I've spent a lot of time in my life working with Logic and ProTools (professional desktop audio applications) so I was relieved when I read these words,

Timing is controlled with high precision and low latency, allowing developers to write code that responds accurately to events and is able to target specific samples, even at a high sample rate. So applications such as drum machines and sequencers are well within reach.

Anyone who is familiar with digital audio will know how the word 'latency' can strike fear into the hearts of anybody who is trying to interface a live instrument with computers. Luckily in this application our metronome works flawlessly allowing the API to schedule with high precision exactly when our audio events should occur. The API allows access to your computer's audio clock. Please correct me if I am wrong, but if you are using an outboard audio interface like myself then you are effectively letting your web app use the clock from your gear. Awesome!

Conclusion

Try the metronome here and let me know what you think. I will be adding new features soon including more sounds (from real instruments!) as well as subdivisions for quarter notes. That is for all of the drummers out there :)

react-metronome's People

Contributors

njmyers avatar

Stargazers

Zane Helton avatar Bilal Allawala avatar tsainei avatar Angus Moncrieff avatar Julien Karst  avatar Mar Canet Sola avatar

Watchers

 avatar

Forkers

mcanet

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.