• Stars
    star
    221
  • Rank 179,773 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A multiplayer piano using UDP sockets that can be played using computer keyboard, in the terminal

piano-rs

Rust Toolchain Build Status

A multiplayer piano using UDP sockets that can be played using computer keyboard, in the terminal.

Screenshots

Video clip

Compiling

You'll need to have Rust compiler and its package manager, Cargo installed to compile piano-rs. If you don't have them already, head over to https://rustup.rs/ to run the installer.

You can then compile piano-rs with:

$ git clone https://github.com/ritiek/piano-rs
$ cd piano-rs
$ cargo build --release

If you're using Ubuntu, you might face the following:

error: failed to run custom build command for `alsa-sys v0.1.1`

In this case, compiling again after installing libasound2-dev should solve the problem:

$ sudo apt-get install libasound2-dev

Usage

Once it compiles, run the binary with:

$ cargo run --release

You can also call the binary directly located in ./target/release/piano-rs.

Additional options to the compiled binary can be passed with cargo such as:

$ cargo run --release -- --help

Play piano in the terminal using PC (computer) keyboard.

USAGE:
    piano-rs [OPTIONS]

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

OPTIONS:
        --host-address <ADDRESS>        Set the host's IP Address and Port to connect to (Default: receiver address)
    -m, --mark-duration <DURATION>      Duration to show piano mark for, in ms (Default: 500)
    -n, --note-duration <DURATION>      Duration to play each note for, where 0 means till the end of note (Default: 0)
    -p, --play-file <FILEPATH>          Play notes from .yml file (Default: None)
    -t, --playback-tempo <AMOUNT>       Set playback speed when playing from file (Default: 1.0)
        --receiver-address <ADDRESS>    Set the IP Address and Port to which the receiver socket will bind to (Default:
                                        0.0.0.0:9999)
    -r, --record-file <FILEPATH>        Record notes to .yml file (Default: None)
        --sender-address <ADDRESS>      Set the IP Address and Port to which the sender socket will bind to. A port of 0
                                        implies to bind on a random unused port (Default: 0.0.0.0:0)
    -s, --sequence <AMOUNT>             Frequency sequence from 0 to 5 to begin with (Default: 2)
    -v, --volume <AMOUNT>               Set initial volume for notes (Default: 1.0)
  • You can press the keys on your computer keyboard to play the piano notes.

  • Increase or decrease the note frequency with ← and β†’ respectively (or hold ctrl or shift while playing).

  • Adjust the duration for how long the notes play for with ↑ and ↓.

  • Adjust the volume of the notes with - and +.

  • You can also record your piano session by passing the command-line argument -r <path/to/save/notes.yml> and play them later on with -p <path/to/save/notes.yml>.

Press the Esc key to exit the game.

NOTE: If you get no sound when you press keys, try running it in a directory containing the assets directory. The note sound files are loaded at runtime and piano-rs will fail to load them if it cannot find the assets directory in your current working directory.

Multiplayer

piano-rs is multiplayer! It can also be enjoyed with friends by sharing the same piano session. Here's how to setup:

On the 1st machine, you would launch piano-rs as usual with:

$ cargo run --release

or

$ ./target/release/piano-rs

On the 2nd machine, you would then pass the IP address of the receiver socket of the 1st machine, which by default binds to 0.0.0.0:9999 and can be overriden with --receiver-address. That means, you would run something like this on the 2nd machine to connect to the 1st machine's piano-rs session:

$ cargo run --release -- --host-address=192.168.1.3:9999

or

$ ./target/release/piano-rs --host-address=192.168.1.3:9999

Here, 192.168.1.3 is the IP address of the 1st machine.

The 2nd machine should now be connected and will share the same piano-rs session as the host machine. Any keys you hit, should be marked with a different color indicator.

Similar to the way you connected the 2nd machine, you can connect any number of machines to share the same piano-rs session!


NOTE: These multiplayer features do not make use of tokio-rs runtime and instead use std::net::UdpSocket for communication, which comes included with the Rust standard library. The major limitation of relying on std::net::UdpSocket is that the network requests are handled sequentially on the basis of first come, first serve. This would be a problem if hundreds of players are connected to the same piano-rs session and are hitting the keys at the same time. Obviously, we could acheive much better performance if we were to handle network requests asynchronously with tokio-rs and futures. Unfortunately, these awesome libraries have a bit of learning curve which I don't have the time to go through at the moment! It will be awesome if someone would like to help here make a transition to asynchronously handle network requests.

The cool devs at tokio-rs have also been trying to lower the learning curve by introducing async and await keywords, similar to Python. However, these keywords at the moment are only available under the recent alpha release of tokio-rs for Rust nightly. See the relevant blog post.

Running tests

$ cargo test

Resources

  • piano-rs uses the same note sounds and key bindings as multiplayerpiano. In fact, the note sound files you see in the assets sub-directory are downloaded from multiplayerpiano itself. If you're a moderator on their website and got a problem with this, let me know and I'll remove and stop using the sound files in this repository.

  • You can use this paste to learn to play some popular songs. If you're interested, I've transcribed a few synthesia YouTube videos in this gist, so they can be played with piano-rs.

License

The MIT License

More Repositories

1

rafy-rs

Rust library to download YouTube content and retrieve metadata
Rust
49
star
2

RAT-via-Telegram

Removed according to regulations
35
star
3

url-to-kindle

Convert a webpage, PDF, etc. from URL to MOBI via pushtokindle.fivefilters.org and ebook.online-convert.com, designed to be run on (jailbroken) Kindles
Python
30
star
4

play-on-kodi

Stream your local/network content directly to Kodi by making HTTP requests
JavaScript
27
star
5

auto-image-cropper

Removes extra white borders to correctly resize canvas
Rust
24
star
6

muxnect

Send input to just about any interactive command-line tool through a local web server
Python
23
star
7

GitFeed

Check your GitHub Newsfeed via the command-line
Python
17
star
8

one-liner-SSH-to-Raspberry-Pi

SSH into your Weaved or Remot3.it connected Raspberry Pi with one command
Shell
15
star
9

trunofficial

[NOT WORKING ANYMORE!] Unofficial API to the Truecaller phone number search
Python
15
star
10

product-key-please

A fun tool that attempts to find product keys for commercial softwares
Python
15
star
11

AskQuora

Quora Q&A right from the command-line
Python
14
star
12

LAN-copy-paste

Copy and paste text across LAN devices
Python
12
star
13

plugin.video.megacmd

A very minimal Kodi addon to stream videos from your MEGA account using MEGAcmd command-line tool
Python
11
star
14

dotfiles

NixOS/EndeavourOS hyprland wezterm zsh nvim powerlevel10k; 11x efficiency ez
Shell
10
star
15

net-mpris

Control a remote D-Bus session as if it was running on the default D-Bus session bus on your machine
Python
9
star
16

ritiek.github.io

Just some of my adventures!
CSS
8
star
17

wordlist-generator

A handy wordlist generator
Rust
7
star
18

shapes-classifier

A simple shape classifier in Keras using CNN to classify shapes from 4 different categories.
Python
7
star
19

telemotion

Uses Linux motion software detection and sends you pics and videos on Telegram
Python
6
star
20

url-decoder

CLI tool to decode URLs back to readable form
Rust
5
star
21

infrared-serial-comm

Transmits data using an IR led to an IR receiver on a Raspberry Pi
C
5
star
22

kodi-telegram

[WIP] A telegram bot for controlling Kodi Media Center
Python
5
star
23

spotify-remote

Web-UI for Spotify Desktop
Python
4
star
24

smartbytes-monitor

Python package to monitor your Airtel broadband network stats like remaining data, days left, etc
Python
4
star
25

deep-learning-practise

dipping my feet in deep-learning waters
Jupyter Notebook
4
star
26

IceClimber-NES

[WIP] A remake of NES IceClimber using PyGame
Python
3
star
27

tinygist

A simple tool to to share gist content to and from clipboard
Go
3
star
28

Netgear-WNR612v3

Source rootfs for Netgear WNR612 v3 Router Firmware v1.0.0.18
Shell
2
star
29

Lyrics4Song

Provides lyrics for almost any song
Python
2
star
30

hide-active-window

Hides the current active window in Windows to keep snoopers away
AutoIt
2
star
31

tupload

Telegram bot to fetch files/text from the client
Python
2
star
32

rust-without-rust

Use Python to execute simple Rust code by running it on https://play.rust-lang.org/
Python
2
star
33

advanced-search

A GUI to make advanced file searches in Windows
AutoIt
2
star
34

email-validator

[OBSOLETE] Checks if an e-mail address exists or not
Python
2
star
35

rabduction

A simple tile climbing game using bevy
Rust
2
star
36

what-anime-is-it

Predicts anime from a video file or image
Shell
1
star
37

ktailscale

wip: tailscale in kual on kindle e-reader
Shell
1
star
38

libbrp

Decompress any .brp replay files that have been generated using Ballistica game engine
C++
1
star
39

travis-test

C++
1
star
40

bs-replay-analyzer

Decompress Bombsquad Replay Files
Rust
1
star
41

AoE2-Scripts

Collection of Age of Empires 2 scripts and macros
AutoIt
1
star
42

ig2gog-trainer

Trainer for Imperium Galactica II GOG Remake v2.2.0.8
C
1
star
43

nativefier-shortcut

[WIP] Menu and desktop shortcuts for apps built with nativefier
Shell
1
star