I’ll then attach the script component I created earlier to each of these game objects, so they make sound and move when the user interacts with them. 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. 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. 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). 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. A portable, interactive, real-time-rendering audio and 3D-physics engine.Because working in Unity is incredibly quick and efficient with the Wolfram Language and UnityLink, I’ve created a playable section of piano, and even learned a bit of music theory in the process.įirst, I determined that building the piano requires the following: And luckily, I had Mathematica, Unity and a few hours to spare. So naturally, it looked like I would have to build one myself-digitally, of course. For me, acquiring a real piano was out of the question I had neither the funds nor space in my small college apartment. You know what’s harder than learning the piano? Learning the piano without a piano, and without any knowledge of music theory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |