![playable virtual piano playable virtual piano](https://cdn.windowsreport.com/wp-content/uploads/2017/03/virtual-piano2-768x370.jpg)
In my piano Scene, I’m going to make a Game Object for each key. You can think of the Scene as an environment, Game Objects as the things in that environment and Components as the behaviors of those things. Scenes contain Game Objects, which in turn act as containers for Components. If you’re new to Unity, here’s a brief description of Scenes. When wrapped in Audio, it creates an audio object that can be played directly in a notebook: For a single note, you simply give it the note name, duration and instrument.
![playable virtual piano playable virtual piano](https://virtualpiano.net/wp-content/uploads/2020/11/Record-your-performances-Virtual-Piano-800px.jpg)
To get the sounds of the piano keys I use the symbol SoundNote, which can generate any note from a large collection of instruments. Whew! With the background out of the way, I can finally get to the code. Note that I also included the C key from the next octave (C5) in the scale, as this helps “round off” the scale: If you take a closer look, you can see that this subsection of our piano contains all seven natural notes and all five accidentals. Here, I’m going to use the C note in the fourth octave (also known as C4 or middle C): Any C note can be chosen as the start of the scale. This scale contains only the natural notes in the order C, D, E, F, G, A and B. Let’s use one of the most common scales-the C major scale. In this blog post, and for simplicity’s sake, I’ll focus on a single musical scale (ordered list of notes), but you can apply this method to create the entire piano. These extra keys allow the scales of A minor and C major to be played in all seven octaves.
PLAYABLE VIRTUAL PIANO FULL
The octaves of a piano are color-coded in this diagram:Ī piano contains seven full octaves, with four extra keys on the ends. Two keys with the same note but in different octaves will have different pitches. The notes can be further divided into octaves, each of which contains 12 keys. Here you can see all 88 keys with their corresponding notes labeled: The ♯ and ♭ symbols stand for sharp and flat, respectively. The remaining 36 keys are black and are used to play the accidentals (A♯/B♭, C♯/D♭, D♯/E♭, F♯/G♭ and G♯/A♭). The modern piano has a total of 88 keys, 52 of which are white and are used to play the natural notes (A, B, C, D, E, F and G).
![playable virtual piano playable virtual piano](https://cdn.lo4d.com/t/screenshot/virtual-piano-3.png)
Since then, it’s undergone many design changes, eventually resulting in a (mostly) standardized key configuration. The piano traces its origins back to early 18th-century Italy, where it was invented by Bartolomeo Cristofori. Understanding the theory behind the physical piano will help us to better recreate it digitally in Unity. What Is a Piano?īefore I dive into the code, let’s explore some of the background on the piano and the musical notes it plays. Using UnityLink, it’s now possible to combine the advantages of the Wolfram Language’s impressive simulations with regards to rendering, audio and physics, with Unity’s efficient packaging of all three into standalone applications for web, desktop, mobile and console platforms. As for the last one, I opted to use the newly introduced UnityLink-a powerful link between the Wolfram Language and the real-time development platform Unity. The first two can be accomplished trivially in the Wolfram Language.
![playable virtual piano playable virtual piano](https://virtualpiano.net/wp-content/uploads/2020/08/Auto-Play-Song-New-Feature-Online-Keyboard-Virtual-Piano.jpg)
You know what’s harder than learning the piano? Learning the piano without a piano, and without any knowledge of music theory.