Sonic π ︰ 傑克魔豆

巨人順著豌豆莖追趕著偷走寶物的傑克

傑克與豌豆[1]Jack and the Beanstalk)是一則英國童話,它是最著名的傑克故事。

1734年首次出現於《傑克‧史普林金與魔豆的故事》(The Story of Jack Spriggins and the Enchanted Bean),1807年時出現在班傑明·塔巴特(Benjamin Tabart)的版本《傑克與魔豆史話》(The History of Jack and the Bean-Stalk),但最普及的是約瑟夫·雅各布(Joseph Jacobs)的版本(1890年)。有看法[2]認為,約瑟夫的版本可能比較接近口語流傳時的版本,因為班傑明的版本中含有說教勸世的內容,而口語流傳時的版本通常比較沒有這類成份。

情節

傑克是個與單親母親同住的少年,家中唯一的經濟來源是一頭乳牛 。直到有一天,母牛已經老到無法生產牛奶賺錢,母親便叫傑克把牛牽到市場上去賣錢。在去市場的途中,傑克遇到了一位欲以「魔豆」交換乳牛的男人,而傑克也答應了。回到家後,母親發現傑克一毛錢也沒賺到,只換來的幾顆不明所以的豆子,盛怒之下把魔豆通通丟到外面,並命令傑克立刻上床睡覺。

一夜之間,魔豆長得飛快,傑克攀著延伸到天上的豆莖,進入了一個天上的世界,並闖入了巨人居住的房子和城堡。巨人回家後,他發現了家裡有「人味」,不過並沒有發現傑克。直到巨人沉沉睡去之後,傑克偷了一袋金幣,並原路逃離這個地方。

之後,傑克曾經回到巨人的住所兩次,並如法炮製在巨人睡著時偷了其他的財寶:一個會下金蛋的鵝(或雞)、以及一個會自動彈奏的豎琴。但是,在傑克想要帶著豎琴離開時,把巨人吵醒了,於是 ,巨人緊緊追趕傑克,傑克便叫母親拿斧頭把豆莖砍斷,讓巨人跌落至死。而傑克和母親便靠著從巨人那裡得到的財寶,過著幸福的日子。

─── 摘自維基百科詞條《Jack and the Beanstalk

 

莫非 Dr . Sam Aaron 博士愛說笑,叫人用『無窮迴圈』 loop 寫程式

5.2 – Iteration and Loops

Looping

If you want something to repeat a lot of times, you might find yourself using really large numbers such as 1000.times do. In this case, you’re probably better off asking Sonic Pi to repeat forever (at least until you press the stop button!). Let’s loop the amen break forever:

loop do
  sample :loop_amen
  sleep sample_duration :loop_amen
end

The important thing to know about loops is that they act like black holes for code. Once the code enters a loop it can never leave until you press stop – it will just go round and round the loop forever. This means if you have code after the loop you will never hear it. For example, the cymbal after this loop will never play:

loop do
  play 50
  sleep 1
end

sample :drum_cymbal_open

Now, get structuring your code with iteration and loops!

 

甚至還能解救,同時有許多這樣的『聲音迴圈』呦?

5.4 – Threads

So you’ve made your killer bassline and a phat beat. How do you play them at the same time? One solution is to weave them together manually – play some bass, then a bit of drums, then more bass… However, the timing soon gets hard to think about, especially when you start weaving in more elements.

What if Sonic Pi could weave things for you automatically? Well, it can, and you do it with a special thing called a thread.

Infinite Loops

To keep this example simple, you’ll have to imagine that this is a phat beat and a killer bassline:

loop do
  sample :drum_heavy_kick
  sleep 1
end

loop do
  use_synth :fm
  play 40, release: 0.2
  sleep 0.5
end

As we’ve discussed previously, loops are like black holes for the program. Once you enter a loop you can never exit from it until you hit stop. How do we play both loops at the same time? We have to tell Sonic Pi that we want to start something at the same time as the rest of the code. This is where threads come to the rescue.

Threads to the Rescue

in_thread do
  loop do
    sample :drum_heavy_kick
    sleep 1
  end
end

loop do
  use_synth :fm
  play 40, release: 0.2
  sleep 0.5
end

By wrapping the first loop in an in_thread do/end block we tell Sonic Pi to run the contents of the do/end block at exactly the same time as the next statement after the do/end block (which happens to be the second loop). Try it and you’ll hear both the drums and the bassline weaved together!

 

細思量!『無窮迴圈』彷彿圜之無端,攬住各色的『聲音種子』!這些『聲子』彼此應和共鳴合奏,正是『音樂』之旨乎??

想來他恐早得『超級對撞機』三昧也!!

那麼創作超級對撞機

SuperCollider

SuperCollider 是一個最初由 James McCartney 在1996年發布的程式語言和聲音編程環境,主要用於實時聲音合成算法作曲[1][2]

自此之後,它逐步變成一個被科學家與藝術家們共同開發和操作聲音的系統。這個高效和有表現力的動態語言,為聲學算法音樂交互式編程提供了一個框架。[3]

在2002年以GNU通用公共許可協議發布,SuperCollider 是自由軟體。 最新的主發行版(3.6.6)在2013年11月發布。[4]

ixiquarks

Screenshot of SuperCollider running the ixiQuarks GUI tools.

之實時聲音合成 scsynth 、程式語言 sclang 和聲音編程環境 scide︰

sc_cube_32x32 SuperCollider

SuperCollider is a platform for audio synthesis and algorithmic composition, used by musicians, artists, and researchers working with sound. It is free and open source software available for Windows, Mac OS X, and Linux.

SuperCollider features three major components:

  • scsynth, a real-time audio server, forms the core of the platform. It features 400+ unit generators (“UGens”) for analysis, synthesis, and processing. Some of the audio techniques it supports include additive synthesis, subtractive, FM, granular, FFT, and physical modelling. You can write your own UGens in C++, and users have already contributed several hundred more to the sc3-plugins repository.
  • sclang, an interpreted programming language, controls scsynth via Open Sound Control. You can use sclang for algorithmic sequencing, connecting your app to external hardware including MIDI controllers, or writing GUIs and visual displays. sclang has a stock of user-contributed extensions called Quarks.
  • scide is an editor for sclang with an integrated help system.

SuperCollider was developed by James McCartney and originally released in 1996. In 2002, he generously released it as free software under the GNU General Public License. It is now maintained and developed by an active and enthusiastic community.

 

是尋找聲子的蹤跡?窮究有聲世界之起源乎!

聲子共和國之理念是音聲共鳴和奏,有聲能與有情水乳交融,宛如一首空靈清麗的詩︰

山居秋暝‧王維

空山新雨後,
天氣晚來秋,
明月松間照,
清泉石上流;
竹喧歸浣女,
蓮動下漁舟,
隨意春芳歇,
王孫自可留。

─ 摘自《PHONON REPUBLIC ︰【聲子共和國】的超級對撞機

※ 註︰

pi@raspberrypi:~ $ ps ax | grep jack
 1410 ?        SLsl   0:11 jackd -R -p 32 -d alsa -d hw:0 -n 3 -p 2048 -o2 -r 44100
 1552 ?        SLl    0:08 /usr/bin/qjackctl
 1671 pts/0    S+     0:00 grep --color=auto jack

 

 

 

天空已現晚霞!祝大家

平安夜有個好夢☆