让我们使用 PC 键盘在终端演奏钢琴 | Linux 中国

2018 年 1 月 21 日 Linux中国 译者:lujun9972
厌倦了工作?那么来吧,让我们弹弹钢琴!是的,你没有看错,根本不需要真的钢琴。我们可以用 PC 键盘在命令行下就能弹钢琴。
-- Sk

本文导航
编译自 | https://www.ostechnix.com/let-us-play-piano-terminal-using-pc-keyboard/ 
 作者 | Sk
 译者 | lujun9972

厌倦了工作?那么来吧,让我们弹弹钢琴!是的,你没有看错,根本不需要真的钢琴。我们可以用 PC 键盘在命令行下就能弹钢琴。向你们介绍一下 piano-rs —— 这是一款用 Rust 语言编写的,可以让你用 PC 键盘在终端弹钢琴的简单工具。它自由开源,基于 MIT 协议。你可以在任何支持 Rust 的操作系统中使用它。

piano-rs:使用 PC 键盘在终端弹钢琴

安装

确保系统已经安装了 Rust 编程语言。若还未安装,运行下面命令来安装它。

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

(LCTT 译注:这种直接通过 curl 执行远程 shell 脚本是一种非常危险和不成熟的做法。)

安装程序会问你是否默认安装还是自定义安装还是取消安装。我希望默认安装,因此输入 1(数字一)。

   
     
     
     
  1. info: downloading installer

  2. Welcome to Rust!

  3. This will download and install the official compiler for the Rust programming

  4. language, and its package manager, Cargo.

  5. It will add the cargo, rustc, rustup and other commands to Cargo's bin

  6. directory, located at:

  7. /home/sk/.cargo/bin

  8. This path will then be added to your PATH environment variable by modifying the

  9. profile files located at:

  10. /home/sk/.profile

  11. /home/sk/.bash_profile

  12. You can uninstall at any time with rustup self uninstall and these changes will

  13. be reverted.

  14. Current installation options:

  15. default host triple: x86_64-unknown-linux-gnu

  16. default toolchain: stable

  17. modify PATH variable: yes

  18. 1) Proceed with installation (default)

  19. 2) Customize installation

  20. 3) Cancel installation

  21. 1

  22. info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'

  23. 223.6 KiB / 223.6 KiB (100 %) 215.1 KiB/s ETA: 0 s

  24. info: latest update on 2017-10-12, rust version 1.21.0 (3b72af97e 2017-10-09)

  25. info: downloading component 'rustc'

  26. 38.5 MiB / 38.5 MiB (100 %) 459.3 KiB/s ETA: 0 s

  27. info: downloading component 'rust-std'

  28. 56.7 MiB / 56.7 MiB (100 %) 220.6 KiB/s ETA: 0 s

  29. info: downloading component 'cargo'

  30. 3.7 MiB / 3.7 MiB (100 %) 173.5 KiB/s ETA: 0 s

  31. info: downloading component 'rust-docs'

  32. 4.1 MiB / 4.1 MiB (100 %) 224.0 KiB/s ETA: 0 s

  33. info: installing component 'rustc'

  34. info: installing component 'rust-std'

  35. info: installing component 'cargo'

  36. info: installing component 'rust-docs'

  37. info: default toolchain set to 'stable'

  38. stable installed - rustc 1.21.0 (3b72af97e 2017-10-09)

  39. Rust is installed now. Great!

  40. To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH

  41. environment variable. Next time you log in this will be done automatically.

  42. To configure your current shell run source $HOME/.cargo/env

登出然后重启系统来将 cargo 的 bin 目录纳入 PATH 变量中。

校验 Rust 是否正确安装:

   
     
     
     
  1. $ rustc --version

  2. rustc 1.21.0 (3b72af97e 2017-10-09)

太棒了!Rust 成功安装了。是时候构建 piano-rs 应用了。

使用下面命令克隆 Piano-rs 仓库:

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

上面命令会在当前工作目录创建一个名为 piano-rs 的目录并下载所有内容到其中。进入该目录:

   
     
     
     
  1. cd piano-rs

最后,运行下面命令来构建 Piano-rs:

   
     
     
     
  1. cargo build --release

编译过程要花上一阵子。

用法

编译完成后,在 piano-rs 目录中运行下面命令:

   
     
     
     
  1. ./target/release/piano-rs

这就是我们在终端上的钢琴键盘了!可以开始弹指一些音符了。按下按键可以弹奏相应音符。使用 左/右 方向键可以在弹奏时调整音频。而,使用 上/下 方向键可以在弹奏时调整音长。

Piano-rs 使用与 multiplayerpiano.com[1] 一样的音符和按键。另外,你可以使用这些音符[2]来学习弹指各种流行歌曲。

要查看帮助。输入:

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

  2. piano-rs 0.1.0

  3. Ritiek Malhotra <ritiekmalhotra123@gmail.com>

  4. Play piano in the terminal using PC keyboard.

  5. USAGE:

  6. piano-rs [OPTIONS]

  7. FLAGS:

  8. -h, --help Prints help information

  9. -V, --version Prints version information

  10. OPTIONS:

  11. -c, --color <COLOR> Color of block to generate when a note is played (Default: "red")

  12. -d, --duration <DURATION> Duration to play each note for, where 0 means till the end of note (Default: 0)

  13. -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[4] 译者:lujun9972 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

LCTT 译者
lujun9972 🌟 🌟 🌟 🌟
共计翻译: 75 篇
贡献时间:54 天

推荐文章

< 左右滑动查看相关文章 >

点击图片、输入文章 ID 或识别二维码直达


登录查看更多
0

相关内容

Rust 是一种注重高效、安全、并行的系统程序语言。
一份简明有趣的Python学习教程,42页pdf
专知会员服务
77+阅读 · 2020年6月22日
【实用书】Python爬虫Web抓取数据,第二版,306页pdf
专知会员服务
122+阅读 · 2020年5月10日
【哈佛《CS50 Python人工智能入门》课程 (2020)】
专知会员服务
115+阅读 · 2020年4月12日
【Amazon】使用预先训练的Transformer模型进行数据增强
专知会员服务
57+阅读 · 2020年3月6日
Transformer文本分类代码
专知会员服务
118+阅读 · 2020年2月3日
报告 | 2020中国5G经济报告,100页pdf
专知会员服务
98+阅读 · 2019年12月29日
2019中国硬科技发展白皮书 193页
专知会员服务
86+阅读 · 2019年12月13日
MIT新书《强化学习与最优控制》
专知会员服务
280+阅读 · 2019年10月9日
msf实现linux shell反弹
黑白之道
49+阅读 · 2019年8月16日
通过Docker安装谷歌足球游戏环境
CreateAMind
12+阅读 · 2019年7月7日
谷歌足球游戏环境使用介绍
CreateAMind
33+阅读 · 2019年6月27日
支持多标签页的Windows终端:Fluent 终端
Python程序员
7+阅读 · 2019年4月15日
自然语言处理 | 使用Spacy 进行自然语言处理
机器学习和数学
19+阅读 · 2018年8月22日
CVE-2018-7600 - Drupal 7.x 远程代码执行exp
黑客工具箱
14+阅读 · 2018年4月17日
爬了自己的微信,原来好友都是这样的!
七月在线实验室
4+阅读 · 2018年1月18日
推荐|基于Python的人脸识别库,离线识别率高达99.38%!
全球人工智能
3+阅读 · 2017年12月25日
Python除了不会生孩子,其他的都会了!
全球人工智能
3+阅读 · 2017年11月9日
Knowledge Flow: Improve Upon Your Teachers
Arxiv
5+阅读 · 2019年4月11日
The Evolved Transformer
Arxiv
5+阅读 · 2019年1月30日
Arxiv
5+阅读 · 2018年10月15日
Arxiv
4+阅读 · 2015年8月25日
VIP会员
相关VIP内容
一份简明有趣的Python学习教程,42页pdf
专知会员服务
77+阅读 · 2020年6月22日
【实用书】Python爬虫Web抓取数据,第二版,306页pdf
专知会员服务
122+阅读 · 2020年5月10日
【哈佛《CS50 Python人工智能入门》课程 (2020)】
专知会员服务
115+阅读 · 2020年4月12日
【Amazon】使用预先训练的Transformer模型进行数据增强
专知会员服务
57+阅读 · 2020年3月6日
Transformer文本分类代码
专知会员服务
118+阅读 · 2020年2月3日
报告 | 2020中国5G经济报告,100页pdf
专知会员服务
98+阅读 · 2019年12月29日
2019中国硬科技发展白皮书 193页
专知会员服务
86+阅读 · 2019年12月13日
MIT新书《强化学习与最优控制》
专知会员服务
280+阅读 · 2019年10月9日
相关资讯
msf实现linux shell反弹
黑白之道
49+阅读 · 2019年8月16日
通过Docker安装谷歌足球游戏环境
CreateAMind
12+阅读 · 2019年7月7日
谷歌足球游戏环境使用介绍
CreateAMind
33+阅读 · 2019年6月27日
支持多标签页的Windows终端:Fluent 终端
Python程序员
7+阅读 · 2019年4月15日
自然语言处理 | 使用Spacy 进行自然语言处理
机器学习和数学
19+阅读 · 2018年8月22日
CVE-2018-7600 - Drupal 7.x 远程代码执行exp
黑客工具箱
14+阅读 · 2018年4月17日
爬了自己的微信,原来好友都是这样的!
七月在线实验室
4+阅读 · 2018年1月18日
推荐|基于Python的人脸识别库,离线识别率高达99.38%!
全球人工智能
3+阅读 · 2017年12月25日
Python除了不会生孩子,其他的都会了!
全球人工智能
3+阅读 · 2017年11月9日
Top
微信扫码咨询专知VIP会员