Sonic π ︰ 美的派☆

在 Sonic π 的教程 Tutorial 裡,Dr . Sam Aaron 博士以一個章節講

11 – MIDI

Once you’ve mastered converting code to music, you might wonder – what’s next? Sometimes the constraints of working purely within Sonic Pi’s syntax and sound system can be exciting and put you into a new creative position. However, sometimes it is essential to break out of the code into the real world. We want two extra things:

  1. To be able to convert actions in the real world into Sonic Pi events to code with
  2. To be able to use Sonic Pi’s strong timing model and semantics to control and manipulate objects in the real world

Luckily there’s a protocol that’s been around since the 80s that enables exactly this kind of interaction – MIDI. There’s an incredible number of external devices including keyboards, controllers, sequencers, and pro audio software that all support MIDI. We can use MIDI to receive data and also use it to send data.

Sonic Pi provides full support for the MIDI protocol enabling you to connect your live code to the real world. Let’s explore it further…

 

可謂對『美的派』之重視也。

故而不用『插頭』 JACK 強大連接功能︰

 

 

 

直接溝通 MIDI IO 哩︰

 

作者借著古早的

KORG USB nanoKEY MIDI keyboard

 

實驗文本範例

use_real_time
live_loop :midi_piano do
note, velocity = sync “/midi/nanokey_midi_1/1/1/note_on”
synth :piano, note: note, amp: velocity / 127.0
end

 

果然 OK 好玩呦☆

 

 

 

 

 

 

 

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

 

 

 

天空已現晚霞!祝大家

平安夜有個好夢☆

 

 

 

 

 

 

Sonic π ︰ 沒有錯誤!

Three Butterfly, by a 14-year-old girl, made by chalk and glue on kraft paper

Child art is the drawings, paintings and other artistic works created by children. It is also referred to as “children’s art” or the “art of children”.

“Child art”

In its primary sense the term was created by Franz Cižek (1865–1946) in the 1890s.

The term “child art” also has a parallel and different usage in the world of contemporary fine art, where it refers to a subgenre of artists who depict children in their works.

Third connotation of “child art” implies art intended for viewing by children, say illustrations in a book for juvenile readers. Such art could be done by a child or a professional adult illustrator.

Scribble by one-year-old.

Smiling person (combined head and body) age 4½

Birch bark document 202,[10]showing symbolic drawing of people, age 6-7 (Onfim)

─── 摘自維基百科詞條《Child art

 

當兒童用『形』和『色』畫畫,如何說那圖畫裡的『對』與『錯』呢?怎麼談天真之眼以及稚嫩的手隨興塗鴉之『好』、『壞』耶?更別講有時還會震攝於其中『抽象』線條地『構圖』精美也!

或許因為兒童

尚未習染,不知常規。

所以能如此乎?!

果然,那又何必給他那麼多的繁文縟節哩!?

因此 Dr .Sam Aaron 博士強調

1.3 – Learning through Play

Sonic Pi encourages you to learn about both computing and music through play and experimentation. The most important thing is that you’re having fun, and before you know it you’ll have accidentally learned how to code, compose and perform.

 

沒有『錯誤』;只有『機會』◎

There are no mistakes

Whilst we’re on this subject, let me just give you one piece of advice I’ve learned over my years of live coding with music – there are no mistakes, only opportunities. This is something I’ve often heard in relation to jazz but it works equally well with live coding. No matter how experienced you are – from a complete beginner to a seasoned live coder, you’ll run some code that has a completely unexpected outcome. It might sound insanely cool – in which case run with it. However, it might sound totally jarring and out of place. It doesn’t matter that it happened – what matters is what you do next with it. Take the sound, manipulate it and morph it into something awesome. The crowd will go wild.

Start Simple

When you’re learning, it’s tempting to want to do amazing things now. However, just hold that thought and see it as a distant goal to reachlater. For now, instead think of the simplest thing you could write which would be fun and rewarding that’s a small step towards the amazing thing you have in your head. Once you have an idea about that simple step, then try and build it, play with it and then see what new ideas it gives you. Before long you’ll be too busy having fun and making real progress.

Just make sure to share your work with others!

 

當然,總有『文法錯誤』之時︰

【a = 1,】

 

『執行錯誤』之處︰

【play X】

 

自也有錯把『共時』和弦︰

2.1 – Your First Beeps

Chords

Playing a note is quite fun, but playing many at the same time can be even better. Try it:

play 72
play 75
play 79

Jazzy! So, when you write multiple plays, they all play at the same time. Try it for yourself – which numbers sound good together? Which sound terrible? Experiment, explore and find out for yourself.

……

8.2 – Chords

Sonic Pi has built-in support for chord names which will return lists. Try it for yourself:

play chord(:E3, :minor)

Now, we’re really getting somewhere. That looks a lot more pretty than the raw lists (and is easier to read for other people). So what other chords does Sonic Pi support? Well, a lot. Try some of these:

  • chord(:E3, :m7)
  • chord(:E3, :minor)
  • chord(:E3, :dim7)
  • chord(:E3, :dom7)

───

 

當成『分時』演奏的可能性︰

【play 72】接著【play 75】之後再【play 79】★

 

 

 

 

 

 

 

Sonic π ︰ 是什麼?

海盜船

忒修斯之船

希臘古羅馬時代的普魯塔克 Plutarch 引用古希臘傳說寫道︰

忒修斯與雅典的年輕人們自克里特島歸來時,所搭之三十槳的船為雅典人留下來當做紀念碑。隨著時間流逝;木材逐漸腐朽,那時雅典人便會更換新的木頭來替代。終於此船的每根木頭都已被替換過了;因此古希臘的哲學家們就開始問著:『這艘船還是原本的那艘忒修斯之船的嗎?假使是,但它已經沒有原本的任何一根木頭了;如果不是,那它又是從什麼時候不是的呢?』

這個『同一性』identity 問題,在邏輯學上叫做『同一律』,與真假不相容的『矛盾律』齊名︰

\forall x, \ x = x

……

一九七二年布萊恩‧柯林漢 Brian Wilson Kernighan  於貝爾實驗室撰寫《Introduction to the Language B》的內部技術文件時,寫了一個『hello, world』的範例程式。其後他與 丹尼斯‧里奇 Dennis M. Ritchie 合著的《The C Programming Language》也保留了這個範例程式。不知怎的這成了一個『傳統』,成了初學者所編寫的第一個程式。現今流行的寫法是『Hello, World!』,不知柯林漢會不會抱怨這是是那個嗎?它的原典是︰

hello, world

,裡頭所有字母全是小寫,『 , 』之後有一『空白』。

Thue 1

Thue 2

現在就讓我們用著 Colagioia 之 Thue 語言寫我們第一支中文的『打招呼』程式︰

打招呼::=~別來無恙
::=
打招呼

那要怎麽『跑』run 這個程式呢?網路雲端上有一個『Thue interpreter in Javascript』的網頁,你可以將這支『哈囉』程式,如左圖般地打入或拷貝,先按 Update 鍵載入程式,然後按 Run 鍵執行。你將見證『打招呼』被改寫成了『別來無恙』!!

……… 《THUE 之改寫系統《三》

 

追循與時變遷之

/sonic-pi

The Live Coding Music Synth for Everyone http://sonic-pi.net

                                       ╘
                                ─       ╛▒╛
                                 ▐╫       ▄█├
                          ─╟╛      █▄      ╪▓▀
                ╓┤┤┤┤┤┤┤┤┤  ╩▌      ██      ▀▓▌
                 ▐▒   ╬▒     ╟▓╘    ─▓█      ▓▓├
                 ▒╫   ▒╪      ▓█     ▓▓─     ▓▓▄
                ╒▒─  │▒       ▓█     ▓▓     ─▓▓─
                ╬▒   ▄▒ ╒    ╪▓═    ╬▓╬     ▌▓▄
                ╥╒   ╦╥     ╕█╒    ╙▓▐     ▄▓╫
                           ▐╩     ▒▒      ▀▀
                                ╒╪      ▐▄
         
             _____             __        ____  __
            / ___/____  ____  /_/____   / __ \/_/
            \__ \/ __ \/ __ \/ / ___/  / /_/ / /
           ___/ / /_/ / / / / / /__   / ____/ /
          /____/\____/_/ /_/_/\___/  /_/   /_/

The Live Coding Music Synth for Everyone.

Sonic Pi is a new kind of musical instrument. Instead of strumming strings or whacking things with sticks – you write code – live.

Sonic Pi has been designed with the aim to find a harmonious balance between three core principles:

  • Simple enough for the 10 year old within you
  • Joyful enough for you to lose yourself through play
  • Powerful enough for your own expressions

Sonic Pi is a complete open source programming environment originally designed to explore and teach programming conceptswithin schools through the process of creating new sounds.

In addition to being an engaging education resource it has evolved into an extremely powerful and performance-ready live coding instrument suitable for professional artists and DJs.

Whilst Education is a core focus it now sits at the intersection between three core domains:

  • Art – providing the means to express yourself and ask new questions of music and notation
  • Technology – exploring questions related to liveness, time and concurrency in programming languages
  • Education – demonstrating that open play rather than rigid structures increases motivation and engagement in the classroom

Again, finding a balance working to the best benefits of all these domains is the objective.

Acknowledgements

Sonic Pi has been developed within the Computer Laboratory at the University of Cambridge with kind support from the Raspberry Pi Foundation, the Broadcom Foundation and pi-top.

 

的步履,彷彿捕捉『聲子派』呦!

今日重讀

1 – Welcome friend 🙂

Welcome to Sonic Pi. Hopefully you’re as excited to get started making crazy sounds as I am to show you. It’s going to be a really funride where you’ll learn all about music, synthesis, programming, composition, performance and more.

But wait, how rude of me! Let me introduce myself – I’m Sam Aaron – the chap that created Sonic Pi. You can find me at @samaaron on Twitter and I’d be more than happy to say hello to you. You might also be interested in finding out more about my Live Coding Performances where I code with Sonic Pi live in front of audiences.

If you have any thoughts, or ideas for improving Sonic Pi – please pass them on – feedback is so helpful. You never know, your idea might be the next big feature!

This tutorial is divided up into sections grouped by category. Whilst I’ve written it to have an easy learning progression from start to finish, feel very free just to dip in and out of sections as you see fit. If you feel that there’s something missing, do let me know and I’ll consider it for a future version.

Finally, watching others live code is a really great way to learn. I regularly stream live on http://youtube.com/samaaron so please do drop by, say hi and ask me lots of questions 🙂

OK, let’s get started…

 

好像那艄『忒修斯之船』引發玄想?

一時暈眩,到底什麼是『程式語言』的經緯呀!?

所以屏氣凝神,且將頭腦放空『歸零』,仔細閱讀內容

 

沿途留意之前不知之物︰

Traditional Note Names

For those of you that already know some musical notation (don’t worry if you don’t – you don’t need it to have fun) you might want to write a melody using note names such as C and F# rather than numbers. Sonic Pi has you covered. You can do the following:

play :C
sleep 0.5
play :D
sleep 0.5
play :E

……

5.5 – Functions

Once you start writing lots of code, you may wish to find a way to organise and structure things to make them tidier and easier to understand. Functions are a very powerful way to do this. They give us the ability to give a name to a bunch of code. Let’s take a look.

Defining functions

define :foo do
  play 50
  sleep 1
  play 55
  sleep 2
end

Here, we’ve defined a new function called foo. We do this with our old friend the do/end block and the magic word define followed by the name we wish to give to our function. We didn’t have to call it foo, we could have called it anything we want such as bar, baz or ideally something meaningful to you like main_section or lead_riff.

Remember to prepend a colon : to the name of your function when you define it.

Calling functions

Once we have defined our function we can call it by just writing its name:

define :foo do
  play 50
  sleep 1
  play 55
  sleep 0.5
end

foo

sleep 1

2.times do
  foo
end

We can even use foo inside iteration blocks or anywhere we may have written play or sample. This gives us a great way to express ourselves and to create new meaningful words for use in our compositions.

 

接著認識使用者界面︰

 

然後嘗試探索其 Ruby 之根,看看是否仍然依舊也☆