mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
translated
This commit is contained in:
parent
442c32650e
commit
0b46ca59ea
@ -1,130 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Compose music as code using Sonic Pi)
|
||||
[#]: via: (https://opensource.com/article/20/3/sonic-pi)
|
||||
[#]: author: (Matt Bargenquast https://opensource.com/users/mbargenquast)
|
||||
|
||||
Compose music as code using Sonic Pi
|
||||
======
|
||||
There's no need for instrumental mastery with this accessible open
|
||||
source program that can turn you into a musical virtuoso.
|
||||
![Bird singing and music notes][1]
|
||||
|
||||
Maybe you're like me, and you learned a musical instrument when you were in school. For me, it was the piano, and later, the viola. However, I've always held that, as my childhood interests shifted towards computers and coding, I subsequently neglected my music practice. I do wonder what I would have done if I'd had something like Sonic Pi when I was younger. Sonic Pi is an open source program that lets you compose and perform music through code itself. It's the perfect marriage of those two worlds.
|
||||
|
||||
Opensource.com is no stranger to Sonic Pi—we [featured an interview][2] with the creator, Dr. Sam Aaron, back in 2015. Since that time, a lot has changed, and Sonic Pi has grown substantially in many ways. It's reached a major new version milestone, with the long-awaited v3.2 release made publically available on February 28, 2020. A growing community of developers is actively contributing to its [GitHub project][3], while an equally thriving community of composers shares ideas and support in the [official forums][4]. The project is now also financially assisted through a [Patreon campaign][5], and Sam himself has been spreading the word of Sonic Pi through schools, conferences, and workshops worldwide.
|
||||
|
||||
What really shines about Sonic Pi is its approachability. Releases are available for many major flavors of OS, including Windows, macOS, Linux, and of course, the Raspberry Pi itself. In fact, getting started with Sonic Pi on a Raspberry Pi couldn't be simpler; it comes pre-installed with [Raspbian][6], so if you have an existing Raspbian-based setup, you'll find it situated in the programming menu.
|
||||
|
||||
Upon loading Sonic Pi for the first time, you'll be greeted with a simple interface with two main areas: an editor in which to write your code, and a section devoted to Sonic Pi's expansive tutorial. For newcomers, the tutorial is an essential resource for learning the basics, featuring accompanying music programs to reinforce each concept being taught.
|
||||
|
||||
If you're following along, let's code ourselves a simple bit of music and explore the potential of live-coding music. Type or paste the following code into the Sonic Pi editor:
|
||||
|
||||
|
||||
```
|
||||
live_loop :beat do
|
||||
sample :drum_heavy_kick
|
||||
sleep 1
|
||||
end
|
||||
```
|
||||
|
||||
Even if you're a Sonic Pi novice, many coders may immediately understand what's going on here. We're playing a drum kick sample, sleeping for a second, and then repeating. Click the Run button or press ALT+R (meta+R on macOS), and you should hear it begin to play.
|
||||
|
||||
This isn't a very exciting song yet, so let's liven it up with a snare playing on the off-beat. Replace the existing code with the block below and Run again. You can leave the existing beat playing while you do this; you'll notice that your changes will be applied naturally, in time with the beat:
|
||||
|
||||
|
||||
```
|
||||
live_loop :beat do
|
||||
sample :drum_heavy_kick
|
||||
sleep 0.5
|
||||
sample :drum_snare_soft
|
||||
sleep 0.5
|
||||
end
|
||||
```
|
||||
|
||||
While we're at it, let's add a hi-hat right before every fourth beat, just to make things a little interesting. Add this new block below our existing one and Run again:
|
||||
|
||||
|
||||
```
|
||||
live_loop :hihat do
|
||||
sleep 3.9
|
||||
sample :drum_cymbal_closed
|
||||
sleep 0.1
|
||||
end
|
||||
```
|
||||
|
||||
We've got our beat going now, so let's add a bassline! Sonic Pi comes with a variety of synths built-in, along with effects filters such as reverb and distortion. We'll use a combination of the "dsaw" and "tech_saw" synths to give it an electronic retro-synth feel. Add the block below to your existing program, Run, and have a listen:
|
||||
|
||||
|
||||
```
|
||||
live_loop :bass do
|
||||
use_synth :dsaw
|
||||
play :a2, attack: 1, release: 2, amp: 0.3
|
||||
sleep 2.5
|
||||
use_synth :tech_saws
|
||||
play :a1, attack: 1, release: 1.5, amp: 0.8
|
||||
sleep 1.5
|
||||
end
|
||||
```
|
||||
|
||||
You'll note above that we have full control over the [ADSR][7] envelope when playing notes, so we can decide when each sound should peak and fade.
|
||||
|
||||
Lastly, let's add a lead synth and try out one of those effects features known as the "slicer." To spice things up, we'll also introduce an element of pseudo-randomness by letting Sonic Pi pick from a series of potential chords. This is where some of the fun improvisation and "happy accidents" can begin to occur. Add the block below to your existing program and Run:
|
||||
|
||||
|
||||
```
|
||||
live_loop :lead do
|
||||
with_fx :slicer do
|
||||
chords = [(chord :A4, :minor7), (chord :A4, :minor), (chord :D4, :minor7), (chord :F4, :major7)]
|
||||
use_synth :blade
|
||||
play chords.choose, attack: 1, release: 2, amp: 1
|
||||
sleep 2
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
Great! Now, we're certainly not going to be competing with Daft Punk any time soon, but hopefully, through this process, you've seen how we can go from a bare beat to something much bigger, in real-time, by adding some simple morsels of code. It is well worth watching one of Sam Aaron's [live coding performances][8] on YouTube for a demonstration of how creative and adaptive Sonic Pi can let you be.
|
||||
|
||||
![Sonic Pi composition example][9]
|
||||
|
||||
Our finished piece, in full
|
||||
|
||||
If you've ever wanted to learn a musical instrument, but felt held back by thoughts like "I don't have rhythm" or "my hands aren't nimble enough," Sonic Pi is a versatile instrument for which none of those things matter. All you need are the ideas, the inspiration, and an inexpensive computer such as the humble Raspberry Pi. The rest is at your fingertips—literally!
|
||||
|
||||
Here are a few handy links to get you started:
|
||||
|
||||
* The Official Sonic Pi [website][10] and [tutorial][11]
|
||||
* [Getting Started with Sonic Pi][12] ([projects.raspberrypi.org][13])
|
||||
* Sonic Pi [Github project][3]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/3/sonic-pi
|
||||
|
||||
作者:[Matt Bargenquast][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/anine09)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/mbargenquast
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/music-birds-recording-520.png?itok=UoM7brl0 (Bird singing and music notes)
|
||||
[2]: https://opensource.com/life/15/10/interview-sam-aaron-sonic-pi
|
||||
[3]: https://github.com/samaaron/sonic-pi/
|
||||
[4]: https://in-thread.sonic-pi.net/
|
||||
[5]: https://www.patreon.com/samaaron
|
||||
[6]: https://www.raspberrypi.org/downloads/raspbian/
|
||||
[7]: https://en.wikipedia.org/wiki/Envelope_(music)
|
||||
[8]: https://www.youtube.com/watch?v=JEHpS1aTKp0
|
||||
[9]: https://opensource.com/sites/default/files/uploads/sonicpi.png (Sonic Pi composition example)
|
||||
[10]: https://sonic-pi.net/
|
||||
[11]: https://sonic-pi.net/tutorial.html
|
||||
[12]: https://projects.raspberrypi.org/en/projects/getting-started-with-sonic-pi
|
||||
[13]: http://projects.raspberrypi.org
|
130
translated/tech/20200307 Compose music as code using Sonic Pi.md
Normal file
130
translated/tech/20200307 Compose music as code using Sonic Pi.md
Normal file
@ -0,0 +1,130 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Compose music as code using Sonic Pi)
|
||||
[#]: via: (https://opensource.com/article/20/3/sonic-pi)
|
||||
[#]: author: (Matt Bargenquast https://opensource.com/users/mbargenquast)
|
||||
|
||||
使用 Sonic Pi 将音乐编成代码
|
||||
======
|
||||
有了这个易于使用的开源程序,不需要掌握乐器,就可以把你变成一个音乐大师。
|
||||
![Bird singing and music notes][1]
|
||||
|
||||
也许你和我一样,在上学的时候学过一种乐器。对我来说,那是钢琴,后来是中提琴。然而,我一直认为,随着我童年的兴趣转向计算机和编码,我后来忽略了音乐练习。我确实想知道,如果我年轻时有 Sonic Pi 这样的东西,我会怎么做。Sonic Pi 是一个开源程序,可以让你通过代码本身来创作和演奏音乐。它是这两个世界的完美结合。
|
||||
|
||||
Opensource.com 对 Sonic Pi 并不陌生,我们早在 2015 年就对其创造者 Sam Aaron 博士[进行了采访][2]。从那时起,很多事情都发生了变化,Sonic Pi 在很多方面都有了很大的发展。它达到了一个重要的新版本里程碑,期待已久的 v3.2 版本已于 2020 年 2 月 28 日公开发布。一个不断壮大的开发者社区正积极为其 [GitHub 项目][3]做出贡献,而一个同样繁荣的作曲家社区则在[官方论坛][4]中分享想法和支持。该项目现在还通过[赞助活动][5]获得了资金支持,而 Sam 本人也在世界各地的学校、会议和研讨会中传播 Sonic Pi 的信息。
|
||||
|
||||
Sonic Pi 真正的闪光点在于它的平易近人。它的版本适用于许多主要的操作系统,包括 Windows、macOS、Linux,当然也包括树莓派本身。事实上,在树莓派上开始使用 Sonic Pi 再简单不过了。它预装了[Raspbian][6],所以如果你有一个基于 Raspbian 的现有设置,你会发现它位于编程菜单中。
|
||||
|
||||
第一次加载 Sonic Pi 时,你会看到一个简单的界面,有两个主要的区域:一个编辑器,可以写你的代码,还有一个区域是 Sonic Pi 的扩展教程。对于新手来说,教程是学习基础知识的重要资源,它有配套的音乐程序来巩固所学的每个概念。
|
||||
|
||||
如果你正在学习,让我们为自己编写一段简单的音乐,探索现场编码音乐的潜力。将以下代码输入或粘贴到 Sonic Pi 编辑器中:
|
||||
|
||||
|
||||
```
|
||||
live_loop :beat do
|
||||
sample :drum_heavy_kick
|
||||
sleep 1
|
||||
end
|
||||
```
|
||||
|
||||
即使你是一个 Sonic Pi 的新手,许多程序员可能马上就会明白这里发生了什么。我们正在播放一个踏板鼓样例,睡眠一秒钟,然后重复。点击运行按钮或按 ALT+R(macOS 上为 meta+R),你应该听到它开始播放。
|
||||
|
||||
这还不是一首非常激动人心的歌曲,所以让我们用一个在非拍子上演奏的小鼓来使它生动起来。用下面的代码块替换现有的代码,然后再次运行。你可以在做这个的时候让现有的节拍继续播放;你会注意到你的改动会自然地应用,与节拍同步:
|
||||
|
||||
|
||||
```
|
||||
live_loop :beat do
|
||||
sample :drum_heavy_kick
|
||||
sleep 0.5
|
||||
sample :drum_snare_soft
|
||||
sleep 0.5
|
||||
end
|
||||
```
|
||||
|
||||
我们在做这个的时候,让我们在每四拍之前添加一个踩镲,让声音变得有趣一些。在现有的程序块下面添加新的程序块,然后再次运行:
|
||||
|
||||
|
||||
```
|
||||
live_loop :hihat do
|
||||
sleep 3.9
|
||||
sample :drum_cymbal_closed
|
||||
sleep 0.1
|
||||
end
|
||||
```
|
||||
|
||||
我们现在已经有了我们的节拍,所以让我们来添加一个基调! Sonic Pi 内置了各种合成器,还有混响和失真等效果滤波器。我们将使用 “dsaw” 和 “tech_saw” 合成器的组合,使其具有电子复古合成器的感觉。将下面的块添加到你现有的程序中,运行,并听一听:
|
||||
|
||||
|
||||
|
||||
```
|
||||
live_loop :bass do
|
||||
use_synth :dsaw
|
||||
play :a2, attack: 1, release: 2, amp: 0.3
|
||||
sleep 2.5
|
||||
use_synth :tech_saws
|
||||
play :a1, attack: 1, release: 1.5, amp: 0.8
|
||||
sleep 1.5
|
||||
end
|
||||
```
|
||||
|
||||
你会注意到上面的内容,当播放音符时,我们可以完全控制[ADSR][7]包络,所以我们可以决定每个声音何时达到峰值和衰减。
|
||||
|
||||
最后,让我们添加一个主音合成器,试试那些被称为“切片机”的效果特征。为了使事情更有趣,我们还将引入一个伪随机的元素,让 Sonic Pi 从一系列潜在的和弦中挑选。这就是一些有趣的即兴创作和“快乐的意外”可以开始发生的地方。在你现有的程序中加入下面的程序块并运行:
|
||||
|
||||
|
||||
```
|
||||
live_loop :lead do
|
||||
with_fx :slicer do
|
||||
chords = [(chord :A4, :minor7), (chord :A4, :minor), (chord :D4, :minor7), (chord :F4, :major7)]
|
||||
use_synth :blade
|
||||
play chords.choose, attack: 1, release: 2, amp: 1
|
||||
sleep 2
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
很好!现在,我们当然不会很快与 Daft Punk 竞争,但希望通过这个过程,你已经看到我们如何通过添加一些简单的代码,实时地从一个单一节拍变成更大的东西。在 YouTube 上观看 Sam Aaron 的[现场编码表演][8]是非常值得的,它展示了 Sonic Pi 可以让你有多大的创造力和适应力。
|
||||
|
||||
![Sonic Pi composition example][9]
|
||||
|
||||
我们完成的作品,完整版
|
||||
|
||||
如果你曾经想学习一种乐器,但又觉得被“我没有节奏感”或“我的手不够灵活”这样的想法所束缚,Sonic Pi 是一种多功能的乐器,这些都不重要。你所需要的只是想法和灵感,以及一台便宜的电脑,如简陋的树莓派。事实上,其余的都在你的指尖上。
|
||||
|
||||
这里有几个方便的链接可以让你开始:
|
||||
|
||||
* 官方 Sonic Pi [网站][10]和[教程][11]
|
||||
* [Sonic Pi 入门][12]([projects.raspberrypi.org][13])
|
||||
* Sonic Pi 的 [Github 项目][3]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/3/sonic-pi
|
||||
|
||||
作者:[Matt Bargenquast][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/mbargenquast
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/music-birds-recording-520.png?itok=UoM7brl0 (Bird singing and music notes)
|
||||
[2]: https://opensource.com/life/15/10/interview-sam-aaron-sonic-pi
|
||||
[3]: https://github.com/samaaron/sonic-pi/
|
||||
[4]: https://in-thread.sonic-pi.net/
|
||||
[5]: https://www.patreon.com/samaaron
|
||||
[6]: https://www.raspberrypi.org/downloads/raspbian/
|
||||
[7]: https://en.wikipedia.org/wiki/Envelope_(music)
|
||||
[8]: https://www.youtube.com/watch?v=JEHpS1aTKp0
|
||||
[9]: https://opensource.com/sites/default/files/uploads/sonicpi.png (Sonic Pi composition example)
|
||||
[10]: https://sonic-pi.net/
|
||||
[11]: https://sonic-pi.net/tutorial.html
|
||||
[12]: https://projects.raspberrypi.org/en/projects/getting-started-with-sonic-pi
|
||||
[13]: http://projects.raspberrypi.org
|
Loading…
Reference in New Issue
Block a user