<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Miltiadis Bouchalakis</title>
    <description>The latest articles on DEV Community by Miltiadis Bouchalakis (@miltiadis).</description>
    <link>https://dev.to/miltiadis</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1229350%2Ffcaf8bb1-2e55-4031-82f5-b8e43afefb2e.jpeg</url>
      <title>DEV Community: Miltiadis Bouchalakis</title>
      <link>https://dev.to/miltiadis</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/miltiadis"/>
    <language>en</language>
    <item>
      <title>Design and Code a Playable Piano with Figma, HTML, SCSS, and JavaScript</title>
      <dc:creator>Miltiadis Bouchalakis</dc:creator>
      <pubDate>Mon, 11 Dec 2023 17:29:17 +0000</pubDate>
      <link>https://dev.to/miltiadis/design-and-code-a-playable-piano-with-figma-html-scss-and-javascript-228g</link>
      <guid>https://dev.to/miltiadis/design-and-code-a-playable-piano-with-figma-html-scss-and-javascript-228g</guid>
      <description>&lt;h2&gt;
  
  
  Introduction to the Digital Piano Project
&lt;/h2&gt;

&lt;p&gt;Welcome to an exciting journey through the world of web development and design, as I share my experience in creating a digital piano from scratch. This project is more than just a showcase of technical skills; it's a vivid illustration of how creativity and coding can harmoniously intertwine to bring a digital masterpiece to life. &lt;/p&gt;

&lt;p&gt;Whether you're a seasoned developer, a design enthusiast, or someone curious about the intricacies of web development, this tutorial is designed to provide valuable insights, practical tips, and a bit of inspiration. Let’s dive into the fascinating process of transforming a simple idea into an interactive and visually appealing digital piano.&lt;/p&gt;

&lt;p&gt;If you want to watch the video instead, you can watch it by clicking the YouTube video below:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/W3bJUUhAb1Q"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;All the code is available for free on &lt;a href="https://youtu.be/W3bJUUhAb1Q?si=RHFrRhshhXOQn977&amp;amp;t=611" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; ( You can find the GitHub link within the video description )&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Designing the Piano in Figma&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The journey begins with the design phase, where I use Figma to create the interface for our digital piano. Figma, known for its adaptability and ease of use, is an excellent tool for such a task. &lt;/p&gt;

&lt;h3&gt;
  
  
  Laying the Foundation
&lt;/h3&gt;

&lt;p&gt;I start by setting up a new design file in Figma, focusing initially on the basic layout. This involves establishing the dimensions of the piano and its positioning on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=F7Ea729IHzPBVVzT&amp;amp;t=115" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipwuyeq4lav74gw2qfep.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Designing the Piano Keys
&lt;/h3&gt;

&lt;p&gt;A key aspect of the design phase in Figma is setting up and using a grid. The grid serves as a foundational tool to ensure that all elements of the piano, especially the keys, are aligned precisely and proportionately.&lt;/p&gt;

&lt;p&gt;I initiate the design process by defining a grid system. This grid helps maintain consistent spacing and alignment across the piano interface. It's particularly important for positioning the piano keys accurately, as their placement needs to mimic the layout of a traditional piano closely.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=AWkQS9uUUZPCyGDP&amp;amp;t=127" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgdn442ywuy1vwx8c2tme.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There we design the white and the black keys. The black keys are shorter and positioned slightly higher, just like on a real piano. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=cNoJdrON2MK_H2bc&amp;amp;t=178" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffwfezt2bt59ez4ud29gw.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;br&gt;
After the keys are in place, I add finer details to the design. This includes making the black and the white keys 3D&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=krzgJKTqMhUZtPz-&amp;amp;t=349" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaihm6ot5i5m5nf7f3dz.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Developing the Piano with the use of Semantic HTML&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Transitioning from the design to development, the first step is to set up the basic HTML structure of our digital piano. I begin by creating a foundational HTML document that will house all the components of our piano.&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating the container
&lt;/h3&gt;

&lt;p&gt;The buttons are organized within a parent container, maintaining a clean and logical HTML structure that mirrors the layout of a traditional piano.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=M0uge6gQRc_6Y0O8&amp;amp;t=734" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk9i7j90y9eaohea13ntb.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Using Buttons for Piano Keys
&lt;/h3&gt;

&lt;p&gt;A crucial aspect of this phase, as detailed in the tutorial, is the use of  elements for the piano keys. Instead of using  elements, I choose  elements for each key because they are more semantically appropriate and accessible.

&lt;/p&gt;
&lt;p&gt;Buttons are inherently interactive and accessible, making them ideal for our piano keys. They support keyboard focus and click interactions out of the box, which is essential for the functionality of our digital piano.&lt;/p&gt;

&lt;p&gt;For each key, I create a  element. The white and black keys are differentiated by class names, allowing for specific styling and functionality to be applied later in the SASS and JavaScript phase.&lt;/p&gt;

&lt;p&gt;I also ensure that each button is properly labeled with aria-labels, providing screen reader users with the necessary information about the function and note of each key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=3Q3SK3743o1swJKN&amp;amp;t=870" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2qhglahavlgzrmu75sro.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make the piano more user-friendly, especially for beginners or those learning music, I add hints to each key which helps identify which keyboard keys the user can use to play the notes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=5SIGb5EuqD8SFooW&amp;amp;t=974" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5sl8lx77u4zyt8xbilj2.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Styling the Piano Keys with SCSS
&lt;/h2&gt;

&lt;p&gt;Next, I delve into the styling aspect, using SASS or SCSS to be specific - a powerful CSS extension language. You’ll see my approach to organizing SASS files and utilizing its advanced features by using Maps instead of Variables to create a simple design system and our components.&lt;/p&gt;
&lt;h3&gt;
  
  
  Utilizing SCSS Maps for Theming
&lt;/h3&gt;

&lt;p&gt;A key feature of my SCSS setup is the use of SCSS maps, particularly the &lt;code&gt;$theme&lt;/code&gt; and &lt;code&gt;$piano&lt;/code&gt; maps. These maps are crucial for organizing and managing the various colors, dimensions, and other stylistic properties used in the piano design.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;$theme&lt;/code&gt; map contains the color scheme and other general design elements that define the overall aesthetic of the piano. This approach allows for easy adjustments and theming, ensuring that changes to the design can be made quickly and consistently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=ZivPZsSmo_89i7qn&amp;amp;t=1219" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb44rwvp86civ8z6vvbo8.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;$piano&lt;/code&gt; map specifically holds the properties related to the piano's design, such as key dimensions, border styles, and positioning. This separation of concerns makes the styling process more manageable, modular and easily updated from one place. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=Bu_v-OIBeCdyY6Qr&amp;amp;t=1577" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxus5iwtcdnc6657dxiu5.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Moreover, if you have multiple themes, you can override them.&lt;/p&gt;
&lt;h3&gt;
  
  
  How you can create a new theme:
&lt;/h3&gt;

&lt;p&gt;You can create a new dark theme or you can do multiple maps having the same keys but different values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftg7dn8ompbz1wdp5t2wi.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Merge the Themes: Merge the &lt;code&gt;$theme&lt;/code&gt; and &lt;code&gt;$dark-theme&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;After you do this you can create a new sass map that has the updated values.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Focj7u4jvv7edltazxup6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Focj7u4jvv7edltazxup6.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Reassign &lt;code&gt;$theme&lt;/code&gt; to &lt;code&gt;$theme-dark&lt;/code&gt;: This is where you switch the theme.
&lt;/h3&gt;

&lt;p&gt;And then have the new colours applied to the theme and frontend instantly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmvhvbsq90faok581glrw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmvhvbsq90faok581glrw.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Styling the White Keys
&lt;/h3&gt;

&lt;p&gt;The white keys are styled with a focus on simplicity and elegance. Using the properties from the &lt;code&gt;$piano&lt;/code&gt; map, I define the height, width, and background color for each white key.&lt;/p&gt;

&lt;p&gt;Additional styles include border properties and subtle shadow effects to create a sense of depth. These shadows are especially important for achieving the 3D effect that makes the keys feel tactile and interactive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=NSAPrN3c8afdpptv&amp;amp;t=2140" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fimyhbmami2d92eyz3rng.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Styling the Black Keys
&lt;/h3&gt;

&lt;p&gt;The black keys require a different approach. They are smaller and positioned differently. Here, I use the values from the SASS maps to define their unique dimensions and positioning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=CWMN8Wp-xlgW1yG8&amp;amp;t=2649" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw9ff0unzpxzf9ohdyvw4.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The color and shadow effects for the black keys are adjusted to make them stand out against the white keys. This involves setting a darker color and tweaking the opacity and spread of the shadows to enhance the 3D appearance.&lt;/p&gt;
&lt;h3&gt;
  
  
  3D interactive Key Styling in a Digital Piano
&lt;/h3&gt;

&lt;p&gt;A standout feature in the digital piano's design is the realistic response of its keys when pressed. This effect is achieved through careful styling in SCSS, particularly in the &lt;code&gt;.is-pressed&lt;/code&gt; state for both black and white keys.&lt;/p&gt;
&lt;h3&gt;
  
  
  Black Keys: A Deeper Perspective
&lt;/h3&gt;

&lt;p&gt;For the black keys, pressing a key triggers a transformation defined by &lt;code&gt;perspective(1500px) rotateX(-6deg)&lt;/code&gt;. This effect creates a visual depth, making the key appear as if it's being pressed down. The larger perspective value enhances the depth illusion, while the rotateX tilt simulates the downward motion.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=M3c4QIr6VTp9nfkV&amp;amp;t=2704" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ehdzdu6hm3tzeawnfhu.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  White Keys: A Subtler Motion
&lt;/h3&gt;

&lt;p&gt;The white keys, in contrast, exhibit a more subtle motion with &lt;code&gt;perspective(330px) rotateX(-2deg)&lt;/code&gt;. This difference reflects the distinct physical characteristics of white piano keys. The transformation is less pronounced yet equally effective in conveying the sense of a key being pressed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9srdpbms68zs6bx6dvsu.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both key types utilize &lt;code&gt;transition: transform 0.2s&lt;/code&gt; to ensure the animation is fluid and natural. This careful timing makes the interaction feel responsive and intuitive.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introducing interactivity with Vanilla JavaScript
&lt;/h2&gt;

&lt;p&gt;As I reach the final part of my tutorial, I delve into how to add interactivity and code functionality using JavaScript. This phase is crucial as it transforms the digital piano from a static design into an interactive musical instrument.&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting Up the JavaScript Environment
&lt;/h3&gt;

&lt;p&gt;Initially, I discuss the JavaScript file setup. Given that we're using Webpack, I explain the use of dynamic imports for styles and how Webpack compiles them efficiently.&lt;/p&gt;

&lt;p&gt;To maintain a clean codebase, I emphasize the importance of separating concerns. Hence, I create a dedicated JavaScript folder, paralleling the structure we used for styles.&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating the Piano Component
&lt;/h3&gt;

&lt;p&gt;The first step in coding the functionality is to create a component named &lt;code&gt;Piano.js&lt;/code&gt;. This component is structured as a constructor function, allowing for reusability in different parts of the application.&lt;/p&gt;

&lt;p&gt;I ensure to export the Piano component using the export operator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=Hey-g9LfQEBRcm70&amp;amp;t=2979" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenq904qcbnrz311321go.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Piano function returns an object containing both &lt;code&gt;playNote&lt;/code&gt; and &lt;code&gt;playNoteByKey&lt;/code&gt; functions. This return statement makes these functions accessible to other parts of the application, adhering to the principles of the Module pattern.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Piano.js&lt;/code&gt; file uses a modular pattern, a common and effective approach in JavaScript, to encapsulate functionality. It starts with importing &lt;code&gt;keyboardMap&lt;/code&gt; from the keybinds module. This map is crucial as it correlates keyboard keys to musical notes, an essential aspect of the piano's interactivity.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;playNote&lt;/code&gt; Function
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=zcKSOwfp4NieKsLj&amp;amp;t=3049" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6zj850s686tbjkyzjbb.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;audio.play()&lt;/code&gt; method is then invoked to play the note. This simple yet effective line of code is the heart of the piano's sound functionality.&lt;/p&gt;

&lt;p&gt;A key aspect of this function is the use of the HTML audio element, a powerful web API for manipulating audio files dynamically. This API allows for playing and pausing audio, which is crucial for a web application like a digital piano.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;index.js&lt;/code&gt; Imports
&lt;/h3&gt;

&lt;p&gt;Inside &lt;code&gt;index.js&lt;/code&gt; or our entry point we import our Styles and Components.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import "./styles/main.scss";&lt;/code&gt; &lt;br&gt;
Imports the main SASS stylesheet, ensuring all styles are applied to the piano interface.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import { Piano } from "./javascript/Piano";&lt;/code&gt; &lt;br&gt;
Imports the Piano function, which encapsulates the core functionality for playing notes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import { keyboardMap } from "./javascript/keybinds";&lt;/code&gt; &lt;br&gt;
Imports the mapping of keyboard keys to piano notes, crucial for enabling keyboard interactivity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=Jpp9BbSJNtmJCrmo&amp;amp;t=3409" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcdyr8nf9nfwyuw2dw4k8.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Initializing the Digital Piano
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;const DigitalPiano = Piano();&lt;/code&gt; &lt;br&gt;
Initializes the digital piano by invoking the Piano function. This instance, DigitalPiano, is now equipped with methods to play notes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=F2t431JGUCvmMyL6&amp;amp;t=3424" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmto2bwlg6baejr880le.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating UI Note-Keybind Map
&lt;/h3&gt;

&lt;p&gt;This function creates a mapping between the data attributes of the piano keys (notes) and the HTML elements themselves. This map is used to find the corresponding DOM element efficiently when a note is played.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=mISU9qXStGkK6w-y&amp;amp;t=3591" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qlwyat3isp5kxvmkkn3.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Handling Mouse Events
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;handleMouseDown&lt;/code&gt; and &lt;code&gt;handleMouseUp&lt;/code&gt; are event handlers for mouse down and up events on each key. When a key is pressed (mouse down), it adds the &lt;code&gt;.is-pressed&lt;/code&gt; class for visual feedback and plays the corresponding note. On mouse up, it removes the is-pressed class.&lt;br&gt;
&lt;code&gt;handleDocumentMouseUp&lt;/code&gt; removes the &lt;code&gt;.is-pressed&lt;/code&gt; class from all keys, ensuring that any stuck keys are released if the mouse is released outside a key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=EENE2HHiooRazaJz&amp;amp;t=3778" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4p5lrh5h1bqlzl7wswce.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Handling Keyboard Events
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;findNoteAndNodeFromKeyPress&lt;/code&gt; is a utility function to find the note and corresponding DOM node based on a keyboard event.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;handleDocumentKeyDown&lt;/code&gt; and &lt;code&gt;handleDocumentKeyUp&lt;/code&gt; are event handlers for keyboard events. They use &lt;code&gt;findNoteAndNodeFromKeyPress&lt;/code&gt; to play the corresponding note and toggle the &lt;code&gt;.is-pressed&lt;/code&gt; class based on key down and up events.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=bMLKy7sYvmtgpQif&amp;amp;t=4276" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frgsoe9o28i1i62kjlsu2.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Adding Event Listeners
&lt;/h3&gt;

&lt;p&gt;The document-level event listeners for &lt;code&gt;mouseup&lt;/code&gt;, &lt;code&gt;keydown&lt;/code&gt;, and &lt;code&gt;keyup&lt;/code&gt; handle global actions like releasing all keys when the mouse button is released, and playing notes based on keyboard input.&lt;br&gt;
Each piano key node has event listeners for &lt;code&gt;mousedown&lt;/code&gt; and &lt;code&gt;mouseup&lt;/code&gt; to handle individual key interactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/W3bJUUhAb1Q?si=ZJN3XtbwvhfCZ-bo&amp;amp;t=4425" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6erqeh5zxtxi1zgxl907.png" alt="Link to YouTube Video"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And there we have it—the final chord in our digital piano creation symphony. Through this journey, we've navigated the harmonious blend of design and development, starting from the conceptual sketches in Figma to the functional, interactive keys brought to life with JavaScript. &lt;/p&gt;

&lt;p&gt;This project wasn't just about building a musical instrument; it was about harmonizing different technologies to create something beautiful and functional. I hope this experience leaves you with not only a deeper understanding of web development and design but also the inspiration to blend art and technology in your future projects. &lt;/p&gt;

&lt;p&gt;Thank you for joining me on this melodious coding journey. Keep experimenting, keep learning, and let your creativity play the next tune!&lt;/p&gt;

&lt;p&gt;If you want to watch the video instead, you can watch it by clicking the YouTube video below:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/W3bJUUhAb1Q"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;All the code is available for free on &lt;a href="https://youtu.be/W3bJUUhAb1Q?si=RHFrRhshhXOQn977&amp;amp;t=611" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; ( You can find the GitHub link within the video description )&lt;/p&gt;



</description>
      <category>design</category>
      <category>css</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
