Let’s play the piano in the terminal using our PC keyboard

It’s boring at work? Let’s guys play the piano! Yes, you read that right. Who needs a real piano? We can now play or learn to play the piano from the command line using our PC keyboard. For the sake of acquaintance Piano-rs Is a simple utility written in the Rust programming language that allows you to play the piano in the terminal using the PC keyboard. It is free, open source and licensed under the MIT license. You can use it on any operating system that supports Rust.

Piano-rs: to play the piano in the terminal using our PC keyboard

Installation

Make sure the Rust programming language is installed on the system. If you haven’t installed Rust yet, run the following command to install it.

curl https://sh.rustup.rs -sSf | sh

The installer will ask if you want to proceed with the installation with the default values ​​or customize the installation or cancel the installation. We will set it with the default values, so we specified one (number one).

[email protected]:~# curl https://sh.rustup.rs -sSf | sh                                                                                                          
info: downloading installer                                                                                                                                   
                                                                                                                                                              
Welcome to Rust!                                                                                                                                              
                                                                                                                                                              
This will download and install the official compiler for the Rust programming                                                                                 
language, and its package manager, Cargo.                                                                                                                     
                                                                                                                                                              
It will add the cargo, rustc, rustup and other commands to Cargo's bin                                                                                        
directory, located at:                                                                                                                                        
                                                                                                                                                              
  /root/.cargo/bin                                                                                                                                            
                                                                                                                                                              
This path will then be added to your PATH environment variable by modifying the                                                                               
profile files located at:                                                                                                                                     
                                                                                                                                                              
  /root/.profile                                                                                                                                              
  /root/.bash_profile                                                                                                                                         
                                                                                                                                                              
You can uninstall at any time with rustup self uninstall and these changes will                                                                               
be reverted.                                                                                                                                                  
                                                                                                                                                              
Current installation options:                                                                                                                                 
                                                                                                                                                              
   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable
  modify PATH variable: yes                                                                                                                                   
                                                                                                                                                              
1) Proceed with installation (default)                                                                                                                        
2) Customize installation                                                                                                                                     
3) Cancel installation                                                                                                                                        
1                                                                                                                                                             
                                                                                                                                                              
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'                                                                                           
223.6 KiB / 223.6 KiB (100 %) 209.0 KiB/s ETA:   0 s                                                                                                          
info: latest update on 2017-10-12, rust version 1.21.0 (3b72af97e 2017-10-09)                                                                                 
info: downloading component 'rustc'                                                                                                                           
 38.5 MiB /  38.5 MiB (100 %)   4.3 MiB/s ETA:   0 s                                                                                                          
info: downloading component 'rust-std'                                                                                                                        
 56.7 MiB /  56.7 MiB (100 %)   9.4 MiB/s ETA:   0 s                                                                                                          
info: downloading component 'cargo'                                                                                                                           
info: downloading component 'rust-docs'                                                                                                                       
info: installing component 'rustc'                                                                                                                            
info: installing component 'rust-std'                                                                                                                         
info: installing component 'cargo'                                                                                                                            
info: installing component 'rust-docs'                                                                                                                        
info: default toolchain set to 'stable'                                                                                                                       
                                                                                                                                                              
  stable installed - rustc 1.21.0 (3b72af97e 2017-10-09)
                                                                                                                                                              
                                                                                                                                                              
Rust is installed now. Great!                                                                                                                                 
                                                                                                                                                              
To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH                                                                                 
environment variable. Next time you log in this will be done automatically.                                                                                   
                                                                                                                                                              
To configure your current shell run source $HOME/.cargo/env

Log out or reboot your system to get the updated bin directory in your PATH.

Check if Rust was installed correctly or not:

rustc --version
rustc 1.21.0 (3b72af97e 2017-10-09)

Rust has been successfully installed. The build time of the piano-rs application is shown in brackets.

A Git clone on the Piano-rs repository with the following command:

git clone https://github.com/ritiek/piano-rs

This command will create a directory called “Piano-rs” in the current working directory and load all content into it. Change to this directory:

cd piano-rs

Finally, run the following command to create Piano-rs:

cargo build --release

The compilation process may take some time.

Application

After the compilation process is complete, run the following command from the directory piano-rs:

./target/release/piano-rs

Here is our piano keyboard in Terminal! It’s time to play some notes. Press keys to play notes. Use the arrow keys LEFT / RIGHTto adjust the frequency of the note as you play. And, use the arrows up downto adjust the length of the note as you play.

We do not know how to play the piano, so we cannot give you instructions on how to play it correctly. A quick google search will help you.

To view the help section:

$ ./target/release/piano-rs -h
piano-rs 0.1.0
Ritiek Malhotra <[email protected]>
Play piano in the terminal using PC keyboard.

USAGE:
 piano-rs [OPTIONS]

FLAGS:
 -h, --help Prints help information
 -V, --version Prints version information

OPTIONS:
 -c, --color <COLOR> Color of block to generate when a note is played (Default: "red")
 -d, --duration <DURATION> Duration to play each note for, where 0 means till the end of note (Default: 0)
 -s, --sequence <SEQUENCE> Frequency sequence from 0 to 5 to begin with (Default: 2)

We have to admit that this is a very cool project. For those who could not afford to buy a piano, use this app. We spent our entire day figuring out how to play the song, but we still haven’t figured it out yet! LOL !!

Sidebar