Linux中國

讓我們使用 PC 鍵盤在終端演奏鋼琴

厭倦了工作?那麼來吧,讓我們彈彈鋼琴!是的,你沒有看錯,根本不需要真的鋼琴。我們可以用 PC 鍵盤在命令行下就能彈鋼琴。向你們介紹一下 piano-rs —— 這是一款用 Rust 語言編寫的,可以讓你用 PC 鍵盤在終端彈鋼琴的簡單工具。它自由開源,基於 MIT 協議。你可以在任何支持 Rust 的操作系統中使用它。

piano-rs:使用 PC 鍵盤在終端彈鋼琴

安裝

確保系統已經安裝了 Rust 編程語言。若還未安裝,運行下面命令來安裝它。

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

(LCTT 譯註:這種直接通過 curl 執行遠程 shell 腳本是一種非常危險和不成熟的做法。)

安裝程序會問你是否默認安裝還是自定義安裝還是取消安裝。我希望默認安裝,因此輸入 1 (數字一)。

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:

/home/sk/.cargo/bin

This path will then be added to your PATH environment variable by modifying the
profile files located at:

/home/sk/.profile
/home/sk/.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 %) 215.1 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 %) 459.3 KiB/s ETA: 0 s
info: downloading component 'rust-std'
 56.7 MiB / 56.7 MiB (100 %) 220.6 KiB/s ETA: 0 s
info: downloading component 'cargo'
 3.7 MiB / 3.7 MiB (100 %) 173.5 KiB/s ETA: 0 s
info: downloading component 'rust-docs'
 4.1 MiB / 4.1 MiB (100 %) 224.0 KiB/s ETA: 0 s
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

登出然後重啟系統來將 cargo 的 bin 目錄納入 PATH 變數中。

校驗 Rust 是否正確安裝:

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

太棒了!Rust 成功安裝了。是時候構建 piano-rs 應用了。

使用下面命令克隆 Piano-rs 倉庫:

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

上面命令會在當前工作目錄創建一個名為 piano-rs 的目錄並下載所有內容到其中。進入該目錄:

cd piano-rs

最後,運行下面命令來構建 Piano-rs:

cargo build --release

編譯過程要花上一陣子。

用法

編譯完成後,在 piano-rs 目錄中運行下面命令:

./target/release/piano-rs

這就是我們在終端上的鋼琴鍵盤了!可以開始彈指一些音符了。按下按鍵可以彈奏相應音符。使用 左/右 方向鍵可以在彈奏時調整音頻。而,使用 上/下 方向鍵可以在彈奏時調整音長。

Piano-rs 使用與 multiplayerpiano.com 一樣的音符和按鍵。另外,你可以使用這些音符來學習彈指各種流行歌曲。

要查看幫助。輸入:

$ ./target/release/piano-rs -h

piano-rs 0.1.0
Ritiek Malhotra <ritiekmalhotra123@gmail.com>
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)

我必須承認這是個超級酷的項目。對於那些買不起鋼琴的人,很推薦使用這款應用。

祝你周末愉快!!

此致敬禮!

via: https://www.ostechnix.com/let-us-play-piano-terminal-using-pc-keyboard/

作者:SK 譯者:lujun9972 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出


本文轉載來自 Linux 中國: https://github.com/Linux-CN/archive

對這篇文章感覺如何?

太棒了
0
不錯
0
愛死了
0
不太好
0
感覺很糟
0
雨落清風。心向陽

    You may also like

    Leave a reply

    您的電子郵箱地址不會被公開。 必填項已用 * 標註

    此站點使用Akismet來減少垃圾評論。了解我們如何處理您的評論數據

    More in:Linux中國