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 之根,看看是否仍然依舊也☆