<font size="8"/>春の海
MuseScore 2.0.3
=== ===
=== ===
D
5
12
1
eighth
down
E
5
48
1
half
down
=== ===
これらの中から、音符の音程を表している D や、音符の長さ 12 などを取り出してSonic Pi用に変換した Sonic Pi のコードの一部が下記です。(拡張子.rbのファイル)
(ここで、a,bは2次元配列です。)
a[0]=[:r,:r,:r,:r,:D5,:E5, ... ] # 音程
b[0]=[4.0,2.0,1.0,0.5,0.5,2.0, ... ] # 長さ
c=[60, ... ] # テンポ
use_synth :dpulse # シンセ音源に dpulseを用いる
for i in 0...a.length # a配列のi要素の数だけ繰り返す
use_bpm c[i] # テンポを指定する
for j in 0...a[i].length # a[i]のjの要素の数だけ繰り返す
play a[i][j], sustain: b[i][j]*0.6, amp: 0.3 # 配列a[i]のj番目の要素を音程として音源を鳴らす。
sleep b[i][j] # 配列b[i]のj番目の要素の数値を拍として間を置く.
end
end
loop do a=File.read("/Users/???/SonicPi_Text_MidiNo.txt").to_f # 保存したファイルのフルパス名を与えます. b=File.read("/Users/???/SonicPi_Text_Amp.txt").to_f c=File.read("/Users/???/SonicPi_Text_Sleep.txt").to_f play a,amp: b sleep c end 例 ファイル SonicPi_Text_MidiNo.txt の中身の例は、 60。 60.5も可能 ファイル SonicPi_Text_Amp.txt の中身の例は、 1.0 ファイル SonicPi_Text_Sleep.txt の中身の例は 0.5 Sonic PiのプログラムをRunした後、テキストエディタ等でファイルの中身を書き換えて、"その都度保存"すると、Sonic Piの動作をリアルタイムに制御できます。参考 rANGEL (PDF)
Sonic Pi --> Processing の例
Sonic Piで同時に鳴るランダムな2つの音の音程と音量をx,y,rとして3つのファイル(場所はProcessingプログラムのフォルダ中)に書き出す。 Processingで、ファイルから値を読み込んで、x、yを中心とし、rを半径とした円をランダムな色で描く。 リアルタイムではあるが、書き出す側と読み込む側の同期はしていない。 Sonic Pi側のプログラム use_debug false use_random_seed 0 # 乱数の種の番号。デフォルトは0 loop do x=rrand(48,96) # MIDIノート番号48〜96 (C3〜C6)の音を実数の乱数で生成。x座標とする y=rrand(48,96) # 同上。y座標とする。 r=rrand(0.1,5) # 0.1〜5.0の実数の乱数。音量とする。 File.write("Processingプログラムへのパス/SonicPi_to_Processing/SPtest1.txt",x) # xの値をProcessingのプログラムフォルダ内のファイルに書き出す。 File.write("Processingプログラムへのパス/SonicPi_to_Processing/SPtest2.txt",y) # yの値を 同上 File.write("Processingプログラムへのパス/SonicPi_to_Processing/SPtest3.txt",r) # rの値を 同上 play [x,y],amp:r # x,yを同時に、音量rで鳴らす。 sleep 0.25 # 0.25拍置く(デフォルト速度では0.25秒) end Processing側のプログラム // Sonic Piの2つの音とその強さの値をProcessingのdataディレクトリにファイル出力し、読み込んでグラフィック表示する。 // Sonic Pi側の書き込み中にProcessing側で読み込むと値がないファイルとなってエラーするため、読み込んだ配列の長さが0かどうかを調べている。 void setup() { size(600, 600); # 画面サイズ background(0); # 背景色を黒に strokeWeight(5); # 線の太さを5ピクセルに colorMode(HSB); # 色モデルをHSBに frameRate(5); # 画面の更新速度を5回/秒に } void draw() { float x=0,y=0,r=0; fill(0,2); # 塗り色を黒、透明度を2に(0が完全透明,255が不透明) rect(-5,-5,width+10,height+10); # 画面全体を薄い半透明の黒の四角形で塗りつぶす String[] s1 = loadStrings("SPtest1.txt"); # SonicPiで書き込んでいる値をファイルから読み込む,x String[] s2 = loadStrings("SPtest2.txt"); # 同上,y String[] s3 = loadStrings("SPtest3.txt"); # 同上,r if(s1.length>0) x=(float(s1[0])-48+1)*width/48.; # 画面サイズに合わせてx座標を作成する。ファイルが空の場合は配列の長さがゼロとなっているので、座標を生成しない。 if(s2.length>0) y=(float(s2[0])-48+1)*height/48.; # 同上 y if(s3.length>0) r=(float(s3[0]))*20.0; # 同上、半径r fill(random(255),255,255); # 塗り色の色相をランダムに設定。彩度と明度は最大。 stroke(random(255),255,255); # 同上、線の色 ellipse(x, y, r, r); # 円を描く // println(x+" "+y+" "+r); }Processing --> Sonic Pi の例
Processing側で、マウスで画面をクリックした場所に円を描く。円の座標を2つの音程とし、円の半径はクリックしていた時間から生成し、それを音量とする。これら3つの値を3つのファイルに書き出す。 Sonic Pi側で3つのファイルを読み込み、2つの音を少しずらして鳴らし、読み込んだ音量で鳴らす。鳴らす間隔は1/4拍に固定。 リアルタイムではあるが、2つのプログラムは、同期していない。 Processing側 // Processing_to_SonicPi PrintWriter fx,fy,fr; float x,y,r; float xmin=48,xmax=96; float msec; void setup(){ size(600,600); background(255); stroke(255,0,0); strokeWeight(1); } void draw(){ fill(255,255,255,5); // 塗り色を白色の透明度5に設定 rect(-5,-5,width+10,height+10); // 半透明の白色の四角形を画面全体に描く } void mousePressed(){ msec=millis(); // マウスボタンがクリックされた時間を記憶する。 } void mouseReleased(){ // マウスボタンが離された時に実行される noFill(); x=mouseX*(xmax-xmin)/width+xmin; // マウスのx座標から音程を生成する. y=mouseY*(xmax-xmin)/height+xmin; // マウスのy座標から音程を生成する. r=map(millis()-msec , 0 , 1000, 0 , 5); // マウスボタンが押されていた時間から音量を生成する. if(r>5) r=5; // 音量の最大値を5とする strokeWeight(r*2); // 線の太さを音量から生成する ellipse(mouseX,mouseY,r*30,r*30); // マウスの座標に音量を直径として円を描く println(x+" "+y+" "+r); fx=createWriter("SPtest1.txt"); // Sonic Piに渡す値を保存するファイルを作成する.x用 fy=createWriter("SPtest2.txt"); // 同上、y用 fr=createWriter("SPtest3.txt"); // 同上、r用 fx.println(x); // xの値をファイルに出力する fy.println(y); // yの値を同上 fr.println(r); // rの値を同上 fx.flush(); // バッファからファイルに書き込む fy.flush(); fr.flush(); fx.close(); // ファイルを閉じる fy.close(); fr.close(); } Sonic Pi側 # Processing_to_SonicPi use_synth :dsaw # 音源の指定 loop do # 無限ループ x=File.open("Processingプログラムへのパス/Processing_to_SonicPi/SPtest1.txt").read.split(" ") # Processingのプログラムフォルダからxの値を読み込む y=File.open("Processingプログラムへのパス/Processing_to_SonicPi/SPtest2.txt").read.split(" ") r=File.open("Processingプログラムへのパス/Processing_to_SonicPi/SPtest3.txt").read.split(" ") play x[0].to_f, amp: r[0].to_f # x座標に元ずく音を音量rで鳴らす sleep 0.05 # 0.05拍置く play y[0].to_f, amp: r[0].to_f # y座標に元ずく音を音量rで鳴らす sleep 0.2 # 0.2拍置く end # .read.split(" ") は、データをスペースで区切って配列の要素にする機能ですが、行末コードによるエラーがこれにによって解消したので、そのまま使用しています。
Sonic Pi 本家で、下記のコードの音を聞くことができます。(Topページの下部で)
Sonic Pi Examples (Officialページのサンプルプログラム) の日本語コメントによる解説
Haunted Bells
loop do # 無限ループを開始 sample :perc_bell, rate: (rrand 0.125, 1.5) # サンプル音源の:per_bellを0.125〜1.5のランダムな速度で再生 sleep rrand(0, 2) # 間隔をランダムに0〜2拍あける. end # 無限ループはここまで
Pentatonic Bleeps
with_fx :reverb, mix: 0.2 do # 全体にエフェクトのリバーブを0.2だけかける. loop do # 無限ループ開始 play scale(:Eb2, :major_pentatonic, num_octaves: 3).choose, release: 0.1, amp: rand # E♭のメジャー・ペンタトニックスケールのオクターブ2から3オクターブ分の音から1音をランダムに選び、余韻0.1拍、強さ1未満で、デフォルトの:beep音(サイン波)を鳴らす。 sleep 0.1 # 0.1拍の間をあける. end # 無限ループここまで end # エフェクトここまで
Tron Bikes
loop do # 無限ループ開始 with_synth :dsaw do # :dsaw 鋸型波形を使う with_fx(:slicer, phase: [0.25,0.125].choose) do # スライサを使い、間隔を0.25拍または0.125拍とする. with_fx(:reverb, room: 0.5, mix: 0.3) do # リバーブを使い、部屋サイズを0.5、混合度合いを0.3とする. start_note = chord([:b1, :b2, :e1, :e2, :b3, :e3].choose, :minor).choose # 開始音を、マイナーコード6種から選んだ一つのコード、からさらに選んだ1音とする. final_note = chord([:b1, :b2, :e1, :e2, :b3, :e3].choose, :minor).choose # 終了音 同上 p = play start_note, release: 8, note_slide: 4, cutoff: 30, cutoff_slide: 4, detune: rrand(0, 0.2), pan: rrand(-1, 0), pan_slide: rrand(4, 8) # 開始音を余韻8拍、前の音からの音程の移動に4拍、ローパスフィルタのカットオフ高さを30(ノート番号)、前の音のカットオフ値からの移動に4拍、音程0.2未満ずらした音を混ぜる、パンは左〜中央、パンの移動に4〜8拍かける. control p, note: final_note, cutoff: rrand(80, 120), pan: rrand(0, 1) # 終了音に対して設定に従い連続的に移動する。カットオフ値は80〜120、パンは、中央から右 end end end sleep 8 # 8拍の間を置く end # 無限ループ終わり
Wob Rhythm
with_fx :reverb do # リバーブをかける in_thread do # 他と並行動作させる. loop do # 無限ループ開始 r = [0.5, 1.0/3, 3.0/5].choose # 音程となる再生速度を3種からランダムに選ぶ 8.times do # 8回繰り返す sample :ambi_choir, rate: r, pan: rrand(-1, 1) # サンプリング音源の:ambi_choirを速度rで、左右のパンはランダムにして再生する。 sleep 0.5 # 0.5拍の間を置く end end end end # メインプログラム with_fx :wobble, phase: 2 do |w| # wobbleの間隔を2拍とし、2拍目のドラム音にモジュレーションをかける. # |w|は使われていないがsleepの後にcotrol w, phase: rrand(0.5, 4) 等により変化を増やせる. with_fx :echo, mix: 0.6 do # エコーを混合度合0.6で適用し、ドラムが減衰しながら3回鳴っているようする. loop do # 無限ループ開始 sample :drum_heavy_kick # サンプル音源のdrum_heavy_kickを鳴らす. sample :bass_hit_c, rate: 0.8, amp: 0.4 # 同時に bass_hit_cを、再生速度0.8、強さ0.4で鳴らす. sleep 1 # 1拍置く end # 無限ループはここまで end # エコーはここまで end # wobbleはここまで
Ocean Waves
with_fx :reverb, mix: 0.5 do # リバーブを混同度合い0.5で適用する loop do # 無限ループ開始 s = synth [:bnoise, :cnoise, :gnoise].choose, amp: rrand(0.5, 1.5), attack: rrand(0, 4), sustain: rrand(0, 2), release: rrand(1, 3), cutoff_slide: rrand(0, 3), cutoff: rrand(60, 80), pan: rrand(-1, 1), pan_slide: 1, amp: rrand(0.5, 1) # 3種のノイズ音源から一つ選び、強さを0.5〜1.5、音の立ち上がり時間を0〜4拍、音の持続時間を0〜2拍、余韻時間を1〜3拍、ローパスフィルタのカットオフ音程の変化時間を0〜3拍、カットオフ音程を60〜80、パンを-1〜1、パンの変化に要する時間を1拍、強さを0.5〜1とする。 control s, pan: rrand(-1, 1), cutoff: rrand(60, 115) # 上記設定から音源をパン-1〜1、カットオフ音程60〜115に変化させる. sleep rrand(2, 3) # 2〜3拍置く. end end
IDM Breakbeat
define :play_bb do |n| # 関数play_bb を定義する.nの値が与えられて呼び出される. sample :drum_heavy_kick # サンプリング音源のdrum_heavy_kickを再生する. sample :ambi_drone, rate: [0.25, 0.5, 0.125, 1].choose, amp: 0.25 if rand < 0.125 # randが0.125以下の場合(1/8の確率で)この行を実行する. # ambi_droneを再生速度4種のいずれかで、強さ0.25で再生する. sample :ambi_lunar_land, rate: [0.5, 0.125, 1, -1, -0.5].choose, amp: 0.25 if rand < 0.125 # 同上 ambi_lunar_landを1/8の確率で再生する. sample :loop_amen, attack: 0, release: 0.05, start: 1 - (1.0 / n), rate: [1,1,1,1,1,1,-1].choose # loop_amenを立ち上がり時間0、余韻時間0.05拍、音源の開始位置1 - (1.0 / n)、再生速度は、7種から選ばれる.1/7の確率で、-1となり、逆再生(スクラッチ音)となる. sleep sample_duration(:loop_amen) / n # サンプル音源loop_amenの長さの半分の時間置く. end loop {play_bb([1,2,4,8,16].choose)} # 無限ループの中で、定義された関数をnの値を5種の中から選んで実行する. # 無限ループは、loop{ } とも書ける. # 関数の引数は、( )で囲っても良い.
Acid Walk
in_thread do # 並列実行するプログラム. use_synth :fm # fm 音源を使う sleep 2 # 2拍置く loop do # 無限ループ開始 28.times do # 28回繰り返す sample :drum_bass_hard, amp: 0.8 # サンプリング音源のdrum_bass_hardを強さ0.8で再生する. sleep 0.25 # 0.25拍置く. play :e2, release: 0.2 # 2オクターブ目のEの音を減衰0.2拍で鳴らす. sample :elec_cymbal, rate: 12, amp: 0.6 # サンプリング音源のelec_cymbalを再生速度12倍、強さ0.6で再生する. sleep 0.25 # 0.25拍置く. end # ここまでを28回繰り返す sleep 4 # 4拍置く. end end # メインプログラム use_synth :tb303 # 音源をth303にする with_fx :reverb do |rev| # リバーブを設定する. loop do # 無限ループ開始 control rev, mix: rrand(0, 0.3) # リバーブのmix値を0〜0.3とする with_fx :slicer, phase: 0.125 do # 1/8拍間隔で音をスライスする sample :ambi_lunar_land, sustain: 0, release: 8, amp: 2 end control rev, mix: rrand(0, 0.6) # リバーブのmix値を0〜0.6に変更する. r = rrand(0.05, 0.3) # 余韻長さとするrを0.05〜0.3とする. 64.times do # 64回繰り返す play chord(:e3, :minor).choose, release: r, cutoff: rrand(50, 90), amp: 0.5 # Eのオクターブ3のマイナーコードから1音を任意に選び、余韻長さr、ローパスフィルタのカットオフ音程50〜90、強さ0.5で鳴らす sleep 0.125 end control rev, mix: rrand(0, 0.6) # リバーブのmix値を0〜0.6に変更する. r = rrand(0.1, 0.2) with_synth :prophet do 32.times do sleep 0.125 play chord(:a3, :m7).choose, release: r, cutoff: rrand(40, 130), amp: 0.7 end end control rev, mix: rrand(0, 0.6) # リバーブのmix値を0〜0.6に変更する. r = rrand(0.05, 0.3) 32.times do play chord(:e3, :minor).choose, release: r, cutoff: rrand(110, 130), amp: 0.4 sleep 0.125 end control rev, mix: rrand(0, 0.6) # リバーブのmix値を0〜0.6に変更する. with_fx :echo, phase: 0.25, decay: 8 do # エコーを位相0.25、減衰を8拍とする. 16.times do # 16回繰り返す play chord([:e2, :e3, :e4].choose, :m7).choose, release: 0.05, cutoff: rrand(50, 129), amp: 0.5 sleep 0.125 end # 16回のループはここまで end # 無限ループはここまで end # リバーブはここまで end # tb303音源はここまで
試しに作ってみた小プログラム集
Sonic Piでプッシュフォンのダイアル音を鳴らす. DTMF tone
# DTMF sound (Dual-Tone Multi-Frequency) dial="0123456789ABCD*#" # 鳴らしたいプッシュボタンを文字列で与える hi=[1209,1336,1477,1633] # 高音側の周波数 lo=[697,770,852,941] # 低音側の周波数 pushButton=[["1","2","3","A"], # プッシュボタンの並び ["4","5","6","B"], ["7","8","9","C"], ["*","0","#","D"]] define :dtmfPlay do |d| # d に鳴らしたいボタンの文字が入り、音を鳴らす関数 for i in 0...4 # lo for j in 0...4 # hi if(d == pushButton[i][j]) # 鳴らしたいボタンに一致する並びを調べる play hz_to_midi(lo[i]),attack: 0.05 ,release: 0.3 # 低音側の音を鳴らす、アタックは弱め、余韻は短め play hz_to_midi(hi[j]),attack: 0.05 ,release: 0.3 # 高音側の音を鳴らす(2音は同時に鳴る) end end end end for i in 0...dial.length puts dial[i] dtmfPlay dial[i] # dialの配列から1文字取り出して、音を鳴らす関数を呼ぶ sleep 0.5 # 間隔を与える end
use_bpm 130 define :tarai do |x,y,z| a=[:D4,:E4,:F4,:G4,:A4,:B4,:C5,:D5,:E5,:F5,:G5,:A5,:B5] 2.times do puts x,y,z play_pattern_timed [a[x+1],a[x+1]+12,a[y+1],a[y+1]+12,a[z+1],a[z+1]+12,a[y+1],a[y+1]+12],0.25 end n=n+1 if(x<=y) return y else return tarai( tarai(x-1,y,z), tarai(y-1,z,x), tarai(z-1,x,y)) end end tarai 10,5,0 最後のreturn文の()は省けないようです。 関数の定義と呼び出しは、 define :tarai do |x,y,z| tarai 10,5,0 を define tarai(x,y,z) tarai(10,5,0) と書いても問題ないようです。 参考 Wikipediaの竹内関数 Tarai Function Music aike氏 竹内関数で音楽生成 aike氏 ハッカーの遺言状──竹内郁雄の徒然苔 第18回:問題児も悪くない
# ( )を使わない表記では、 define :gcd do |a,b| return a if b == 0 gcd b, a % b end puts gcd 12,18 # ( )を使う表記では、 def gcd(a, b) return a if b == 0 gcd(b, a % b) end puts gcd(12,18)
プログラムは、下記の5行と非常に簡単に記述できます。 pi=File.open("ファイル pi1000000.txt へのパス").read # ファイルの置き場所は任意. デスクトップ等でも可. for i in 0...pi.length play pi.slice(i, 1).to_i*2+60 sleep 0.125 end この設定では、演奏の完了には約37時間かかります。 二桁ずつ取り出すなどの改良も容易です。 for i in (0...pi.length).step(2) play pi.slice(i, 2).to_i+40 sleep 0.125 endなお、3.14の2文字目のピリオドは無視しています。
prime=File.open("ファイル p1.txt へのパス").read.split(" ") for i in 0...prime.length-1 play 60+prime[i+1].to_i-prime[i].to_i sleep 0.125 end
file= :loop_amen_full # 音を与える sampleTime = sample_duration(file) # 音の長さを調べる delayTime = 0.2 # ディレイ時間 decayFactorIni = 0.4 # 減衰ファクター decayFactor = decayFactorIni sample file (sampleTime/delayTime).times do sleep delayTime sample file, amp: decayFactor decayFactor = decayFactor * decayFactorIni end
use_random_seed Time.new.usec # 乱数の系列をミリ秒によって変える loop do f1=hz_to_midi(rrand(4000, 5000)) # さえずりの高音側周波数の範囲をHzで与えmidi番号に f2=hz_to_midi(rrand(1000, 3000)) # さえずりの低音側周波数の範囲をHzで与えmidi番号に s= play f1, attack:0.02, sustain:0.2, release:0, note_slide:0.1, pan_slide: 0.1, amp:rrand(0.1,2), amp_slide: 0.1 # 高音側の音を鳴らす sleep 0.05 # 非常に短く伸ばす control s, note: f2, pan:rrand(-1,1), amp:rrand(0.1,2) # 低音側の音を鳴らす sleep 0.05 # 非常に短く伸ばす control s, note: f1, pan:rrand(-1,1), amp:rrand(0.1,2) # 高音側の音を鳴らす sleep rrand(0.1,1) # さえずりの時間間隔は少し長めに endずっと聞いていると、あまり気持ちよくはありません。音量や間隔や周波数に 1/fゆらぎ を取り入れると心地よくなると思われます。(次節)
use_random_seed Time.new.usec # 現在のミリ秒値で乱数系列を選択 define :x1f do |x| if x<0.5 x=x+2*x*x else x=x-2*(1-x)*(1-x) end if x<0.01 # 両端付近の処理.この部分は適当です。 x=rrand(0.01,0.1) elsif x>0.99 x=rrand(0.9,0.99) end return x end x1=rand;x2=rand;x3=rand # 初期値 loop do x1=x1f x1 # 関数 x1fに引数x1を与え、戻り値x1を得る. x1=x1f(x1)と書いてもよい. x2=x1f x2 x3=x1f x3 # 再生速度の変化0.9〜1.1、左右のパン-1〜1、音量0.5〜1.5、時間間隔0〜2 sample :misc_crow,rate:0.9+x1/5,pan:x2*2-1,amp:x3+0.5 sleep x3*2 end
# n Equal Temperament Music nEqualTemperament=12 # 12平均律の場合。 この数値を6,10,13,31,100 等、自由に変更して下さい。 A4=440 # Tuning チューニングを変更したい場合 C5=A4*2.0**(3.0/12.0) C0=C5/(2.0**5) nET=[] centerC=nEqualTemperament*4 for i in 0..nEqualTemperament*9 nET[i]=hz_to_midi(C0*2.0**(i/nEqualTemperament.to_f)) end # 以上が音程の生成。以下は演奏。 use_synth :tri # 音色 :triを:pianoに変更すれば 微分音ピアノ になります。 use_bpm 160 # 速度 a=[] b=[] # かえるのうた Kaeruno uta a[0]=[:C4,:D4,:E4,:F4,:E4,:D4,:C4] # ドレミファミレド b[0]=[1,1,1,1,1,1,2] a[1]=[:E4,:F4,:G4,:A4,:G4,:F4,:E4] # ミファソラソファミ b[1]=[1,1,1,1,1,1,2] a[2]=[:C4,:C4,:C4,:C4] # ドドドド b[2]=[2,2,2,2] a[3]=[:C4,:C4,:D4,:D4,:E4,:E4,:F4,:F4,:E4,:D4,:C4] # ドドレレミミファファミレド b[3]=[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1,1,2] # 3部の輪唱で演奏する。 live_loop :lop1 do for i in 0...a.length for j in 0...a[i].length play nET[a[i][j]-(60-centerC)],sustain:b[i][j]*0.9,pan:-1 sleep b[i][j] end end end sleep 8 # 8拍後に第2パートをスタートする live_loop :lop2 do for i2 in 0...a.length for j2 in 0...a[i2].length play nET[a[i2][j2]-(60-centerC)],sustain:b[i2][j2]*0.9,pan:0 sleep b[i2][j2] end end end sleep 8 # さらに8拍後に第3パートをスタートする live_loop :lop3 do for i3 in 0...a.length for j3 in 0...a[i3].length play nET[a[i3][j3]-(60-centerC)],sustain:b[i3][j3]*0.9,pan:1 sleep b[i3][j3] end end end 曲を「かえるのうた」から、「フレールジャック」に変更する場合には、上記のaとbの配列[0]から[3]の8行を、下記2行に置き換えてください。 # Frere Jacques a[0]=[:C4,:D4,:E4,:C4,:C4,:D4,:E4,:C4,:E4,:F4,:G4,:E4,:F4,:G4,:G4,:A4,:G4,:F4,:E4,:C4,:G4,:A4,:G4,:F4,:E4,:C4,:C4,:G3,:C4,:C4,:G3,:C4] b[0]=[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,2.0,0.5,0.5,0.5,0.5,1.0,1.0,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,2.0,1.0,1.0,2.0]
path="各使用環境でのファイルへのpath /genome_Joichi_Ito_Full_20160218143309_1-1000.txt" d = [] open(path){|f| d = f.readlines} for i in 0...d.length if d[i].index("#") else puts d[i][d[i].index("\t",-6)+1...d[i].length-1] dd=d[i][d[i].index("\t",-6)+1...d[i].length-1] for j in 0...dd.length ddd=dd[j] ddd="D" if dd[j]=="I" ddd="E" if dd[j]=="T" ddd="B" if dd[j]=="-" play ddd sleep 0.5 # 音の間隔 end end endなお、御本人からTwitterにて,いいねとリツイートをいただいていますので公認と考えれれます。
path="ファイルへのパス genome_Joichi_Ito_Full_20160218143309.txt" File.open(path) do |file| file.each_line do |dataLine| if !dataLine.index("#") d=dataLine.chomp.split("\t")[3] for i in 0...d.length dd=d[i] dd="D" if d[i]=="I" dd="E" if d[i]=="T" dd="B" if d[i]=="-" play dd sleep 0.1 end end end end========================================
path="各使用環境でのファイルへのpath /genome_Joichi_Ito_Full_20160218143309_1-1000.txt" use_debug false d = [] open(path){|f| d = f.readlines} with_fx :panslicer do for i in 0...d.length if d[i].index("#") else puts d[i][d[i].index("\t",-6)+1...d[i].length-1] dd=d[i][d[i].index("\t",-6)+1...d[i].length-1] for j in 0...dd.length ddd=dd[j] ddd="D" if dd[j]=="I" ddd="E" if dd[j]=="T" ddd="B" if dd[j]=="-" ddd=ddd+"3" puts ddd for k1 in 0..9 play chord(ddd,:M,num_octaves:3,invert:k1),amp:rrand(0.5,2),attack:0.1 sleep 0.25 end for k2 in 9.downto(0) play chord(ddd,:m,num_octaves:3,invert:k2),amp:rrand(0.5,2),attack:0.1 sleep 0.25 end end end end end
# Sonification, Buble Sort Music n=8 # 音の数 a=[] for i in 0...n a[n-i-1]=scale(60,:major,num_octaves:3)[i] end # n*2.times do # Randomization # i=rrand_i(0,n-1) # j=rrand_i(0,n-1) # a[i],a[j]=a[j],a[i] # end for i in 0...n-1 for k in 0...n play a[k] sleep 0.1 end puts "-----------" sleep 1 for j in 0...(n-1-i) if a[j]>a[j+1] then a[j],a[j+1]=a[j+1],a[j] end end end #(n-1).downto(0) do |k| # 逆順に鳴らす場合下のforの代わりに for k in 0...n play a[k] sleep 0.2 end
# Random walk around on the Circle of Fifth use_debug false use_random_seed Time.new.usec use_synth :pluck i=0 loop do 2.times do play_pattern_timed (chord 48 + i%12, :major),0.01 puts i/7, note_info(48 + i%12) sleep 0.5 end i=i+(rrand_i(0,2)-1)*7 end
#日本と英国の余命データの可聴化 # Sonification of Japan vs UK Life Expectancy Sounds use_synth :piano require 'csv' path="path to /indicator life_expectancy_at_birth.csv" d=CSV.read(path, headers: false) for i in 0...d.length C1=i if d[i][0]=="Japan" C2=i if d[i][0]=="United Kingdom" # "United States" end for j in 1...d[C1].length puts d[0][j] #play 72+(d[C1][j].to_f-d[C2][j].to_f)*1.5,amp:3 # play difference play d[C1][j].to_f,amp:3,pan:-1 # play JP from left sleep 0.1 play d[C2][j].to_f,amp:3,pan:1 # play UK from right sleep 0.1 end
a=midi_to_hz(:C4) # 開始音 play hz_to_midi(a);sleep 1 b=a 12.times do b=b*1.5 b=b/2.0 if b>a*2 play hz_to_midi(b);sleep 1 end puts "Pythagorean comma=",(hz_to_midi(b)-hz_to_midi(a))*100 play [hz_to_midi(a),hz_to_midi(b)],sustain:4 # ピタゴラスのコンマによる唸り
a=[[600,600],[600,550],[600,500],[600,400],[600,300],[600,200]] for i in 0...a.length play hz_to_midi(a[i][0]),amp:3,sustain:2,pan:-1 play hz_to_midi(a[i][1]),amp:3,sustain:2,pan:1 sleep 2 end配列中の周波数[ , ]の左右を入れ替えると、グラフのXY軸が交換します。panの値の入れ替え(1と-1)でも同様です。
use_bpm 60 #f=" Path to the file So_What_solo.wav" a=[] b=[] a[0]=[:r,:D5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.063,0.278,0.244,0.404,0.484,0.046,0.665,0.168,0.349,0.303,0.589,0.265,0.185,0.248,0.206,0.278,0.942,0.349,0.273,0.198,2.137,0.564,0.762,0.316,0.324,0.391,0.403,2.989,0.219,0.231,0.135,0.286,0.265,0.326,0.326,0.24,0.614,0.24,0.208,0.185,0.406,0.303,2.865,0.328,0.371,0.109,0.273,0.228,0.209,0.219,0.21,0.202,0.395,0.29,1.035,0.376,0.074,0.909,0.442,0.29,0.252,0.37,0.299,1.935,0.248,0.181,0.24,0.206,0.219,0.21,0.244,0.189,0.429,0.459,0.328,0.177,0.341,0.265,0.177,0.244,0.202,0.252,0.24,0.391,2.259,0.303,0.21,0.265,0.589,2.524,0.387,1.94,0.442,0.888,0.328,0.261,0.341,2.163,0.74,2.676,0.21,0.366,0.438,0.745,0.337,1.59,0.728,2.352,0.417,0.759,0.204,0.244,0.179,0.334,0.566,0.82,0.297,0.258,0.751,0.316,0.285,0.297,0.492,1.611,0.171,0.251,0.238,0.074,0.294,0.411,0.334,2.905,0.169,0.257,0.319,0.461,0.294,0.158,0.241,0.201,0.272,0.619,0.269,0.179,0.247,0.161,0.362,1.803,1.154,0.238,1.544,0.244,0.359,0.411,0.464,0.303,0.628,1.977,0.189,0.269,0.199,0.222,0.223,0.65,0.179,0.136,0.13,0.878,0.436,0.217,0.384,2.19,0.254,0.189,0.272,1.046,1.825,0.73,0.21,0.195,0.167,0.377,0.977,0.418,0.306,0.439,0.167,0.408,2.051,0.176,0.238,0.204,0.213,0.198,0.275,0.217,0.823,0.696,0.49,0.107,0.294,0.186,0.387,0.513,3] #sample f, amp:3 use_synth :pretty_bell in_thread do for i in 0...a.length for j in 0...a[i].length play a[i][j], amp:3 sleep b[i][j] end end endSo What(マイルスのソロ部分のみ)
use_bpm 60 a=[] b=[] # Marcel Moyse a[0]=[:r,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:C6,:B5,:Bf5,:Bf5,:A5,:B5,:Af5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D6,:Df6,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Df4,:Gf4,:F4,:E4,:Df4,:A4,:G4,:Df4,:B4,:A4,:G4,:F4,:Ef4,:Ef4,:Df4] b[0]=[1,1.409,0.109,0.102,0.882,0.114,0.098,0.656,0.338,0.307,0.287,1.393,0.202,0.149,4.689,1.046,0.104,0.083,0.752,0.116,0.08,0.633,0.352,0.237,0.21,1.398,0.21,0.155,2.306,0.433,0.27,0.247,0.201,0.189,0.163,0.06,0.524,0.439,1.052,0.183,0.149,2.21,0.422,0.264,0.216,0.112,0.672,0.166,4.153,1.816,4.538,3.286,1.163,0.109,0.128,0.746,0.125,0.088,0.652,0.409,0.279,0.202,1.18,0.109,0.078,0.594,0.101,0.098,0.566,0.295,0.218,0.19,0.256,0.068,0.502,0.315,0.21,2.503,0.596,0.324,0.284,0.181,0.179,0.148,0.105,0.19,0.052,0.373,0.26,0.202,2.13,0.383,0.164,0.132,0.794,0.109,0.056,0.14,0.658,0.158,0.141,0.087,0.868,0.234,0.172,0.192,0.411,0.058,0.526,0.496,1.543,0.649,0.493,0.29,0.097,0.262,0.278,0.232,0.056,0.463,0.431,0.395,0.095,0.91,1.149,0.571,0.102,0.437,0.326,0.559,0.604,0.742,1.008,0.38,0.064,0.508,0.697,1.809,2.03,0.242,0.108,0.367,0.297,0.541,0.647,0.785,0.949,0.298,0.062,0.394,0.398,1.132,1.966,0.344,0.133,0.124,1.821,0.326,0.195,0.159,0.142,0.115,0.492,0.096,0.081,0.089,0.476,0.275,0.174,1.645,0.339,0.233,0.214,0.17,0.172,0.271,0.189,0.128,0.168,0.087,0.096,0.101,0.096,0.088,0.079,0.127,0.07,0.064,0.095,0.972,0.298,0.08,0.061,0.073,0.062,0.079,0.056,0.095,0.618,0.258,0.088,0.098,0.066,0.074,0.071,0.057,0.067,0.065,0.588,0.081,0.085,0.076,4.246,1.527,0.099,0.081,0.647,0.101,0.093,0.676,0.366,0.222,0.375,1.473,0.285,0.076,0.408,0.222,1.723,0.083,0.103,0.593,0.113,0.086,0.663,0.494,0.385,0.516,0.415,0.219,0.122,0.122,0.115,0.105,0.606,0.344,0.307,0.246,0.419,0.2,0.139,0.128,0.104,0.115,0.601,0.399,0.382,1.91,0.399,0.082,0.582,0.736,3.161,0.662,0.767,3.286,4.132,0.81,0.874,0.866,0.987,0.282,4.946] use_synth :pretty_bell in_thread do for i in 0...a.length for j in 0...a[i].length play a[i][j], amp:2.5, release:b[i][j]+0.3 sleep b[i][j] end end end 奏者を変更するには、上記のプログラム中の配列a,bを下記と入れ替えて下さい。 # Marcel Moyse a[0]=[:r,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:C6,:B5,:Bf5,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Gf4,:G4,:C5,:Gf4,:G4,:Df5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Af4,:B4,:Df5,:E5,:Af5,:Af5,:B5,:Df6,:Ef6,:Bf5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Gf5,:F5,:Ef5,:Df5,:Bf4,:Af4,:Df4,:Ef4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Gf5,:F5,:Ef5,:Df5,:Bf4,:Df5,:Ef5,:Gf5,:A5,:Af5,:G5,:Gf5,:Ef5,:D5,:Df5,:C5,:A4,:Af4,:G4,:Gf4,:Ef4,:Gf4,:F4,:E4,:Ef4,:F4,:E4,:Ef4,:Gf4,:F4,:E4,:Ef4,:Gf4,:F4,:E4,:Ef4,:F4,:E4,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0.315,0.21,2.503,0.596,0.324,0.284,0.181,0.179,0.148,0.105,0.19,0.052,0.373,0.26,0.202,2.13,0.383,0.164,0.132,0.794,0.109,0.056,0.14,0.658,0.158,0.141,0.087,0.868,0.234,0.172,0.192,0.411,0.058,0.526,0.496,1.543,0.649,0.493,0.29,0.097,0.262,0.278,0.232,0.056,0.463,0.431,0.395,0.095,0.91,1.149,0.571,0.102,0.437,0.326,0.559,0.604,0.742,1.008,0.38,0.064,0.508,0.697,1.809,2.03,0.242,0.108,0.367,0.297,0.541,0.647,0.785,0.949,0.298,0.062,0.394,0.398,1.132,1.966,0.344,0.133,0.124,1.821,0.326,0.195,0.159,0.142,0.115,0.492,0.096,0.081,0.089,0.476,0.275,0.174,1.645,0.339,0.233,0.214,0.17,0.172,0.271,0.189,0.128,0.168,0.087,0.096,0.101,0.096,0.088,0.079,0.127,0.07,0.064,0.095,0.972,0.298,0.08,0.061,0.073,0.062,0.079,0.056,0.095,0.618,0.258,0.088,0.098,0.066,0.074,0.071,0.057,0.067,0.065,0.588,0.081,0.085,0.076,4.246,1.527,0.099,0.081,0.647,0.101,0.093,0.676,0.366,0.222,0.375,1.473,0.285,0.076,0.408,0.222,1.723,0.083,0.103,0.593,0.113,0.086,0.663,0.494,0.385,0.516,0.415,0.219,0.122,0.122,0.115,0.105,0.606,0.344,0.307,0.246,0.419,0.2,0.139,0.128,0.104,0.115,0.601,0.399,0.382,1.91,0.399,0.082,0.582,0.736,3.161,0.662,0.767,3.286,4.132,0.81,0.874,0.866,0.987,0.282,4.946] # Severino Gazzelloni a[0]=[:r,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:C6,:B5,:Bf5,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Gf4,:G4,:C5,:Gf4,:G4,:Df5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Af4,:B4,:Df5,:E5,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,:F5,:E5,:Df5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Df4,:Gf4,:F4,:E4,:Df4,:A4,:G4,:Df4,:B4,:A4,:G4,:F4,:Ef4,:Ef4,:Df4] b[0]=[1,2.634,0.167,0.189,1.994,0.211,0.167,0.669,0.589,0.4,0.306,2.125,0.386,0.215,5.006,2.121,0.149,0.164,1.841,0.16,0.149,0.659,0.426,0.295,0.204,1.437,0.266,0.178,1.976,0.255,0.193,0.196,0.135,0.164,0.171,0.113,0.462,0.182,1.184,0.275,0.242,2.527,0.367,0.28,0.173,0.16,1.504,0.393,4.391,1.957,3.156,5.761,2.045,0.16,0.142,1.721,0.127,0.196,0.557,0.448,0.44,1.11,1.557,0.196,0.153,1.499,0.226,0.229,0.644,0.378,0.287,0.131,0.335,0.055,0.542,0.324,0.218,2.547,1.055,0.462,0.269,0.211,0.2,0.211,0.156,0.236,0.073,0.531,0.251,0.284,2.638,0.335,0.16,0.138,1.321,0.135,0.171,0.131,1.099,0.167,0.131,0.084,1.31,0.251,0.258,0.233,0.544,0.047,0.569,0.626,2.86,0.731,0.64,0.524,0.071,0.52,0.471,0.362,0.085,0.457,0.74,0.453,0.095,0.524,0.875,0.402,0.095,0.491,0.58,0.653,0.66,0.788,2.097,0.573,0.093,0.728,0.631,2.394,2.92,0.48,0.138,0.653,0.477,0.646,0.604,0.708,1.084,0.564,0.155,0.478,0.349,1.503,2.285,0.282,0.155,0.173,2.363,0.444,0.366,0.278,0.271,0.176,1.133,0.333,0.171,0.136,0.502,0.446,0.313,2.625,0.533,0.346,0.226,0.173,0.204,0.218,0.173,0.085,0.1,0.116,0.122,0.335,0.14,0.182,0.109,0.173,0.12,0.118,0.151,1.946,0.189,0.302,0.073,0.076,0.089,0.047,0.067,0.06,0.058,0.069,0.08,0.055,0.069,0.042,0.082,0.082,1.028,0.126,0.267,0.096,0.062,0.089,0.049,0.095,0.085,0.064,0.095,0.08,0.073,0.069,0.082,0.056,0.096,0.044,0.156,1.403,0.32,0.195,0.233,6.409,3.063,0.18,0.124,1.937,0.124,0.178,0.598,0.491,0.62,1.161,2.172,0.238,0.102,0.606,0.6,3.091,0.207,0.153,1.346,0.162,0.133,0.508,0.484,0.546,1.926,1.01,0.271,0.198,0.196,0.169,0.147,0.469,0.444,0.558,1.963,0.777,0.182,0.151,0.189,0.115,0.135,0.566,0.557,0.906,3.629,0.946,0.236,0.995,1.044,2.703,1.181,1.483,3.866,5.723,1.168,0.951,1.384,2.832,0.819,7.308] #Jean-Pierre Rampal a[0]=[:r,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:C6,:B5,:Bf5,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Gf4,:G4,:C5,:Gf4,:G4,:Df5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Af4,:B4,:Df5,:E5,:Af5,:Af5,:B5,:Df6,:Ef6,:Bf5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Gf5,:F5,:Ef5,:Df5,:Bf4,:Af4,:Df4,:Ef4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Gf5,:F5,:Ef5,:Df5,:Bf4,:Df5,:Ef5,:Gf5,:A5,:Af5,:G5,:Gf5,:Ef5,:D5,:Df5,:C5,:A4,:Af4,:G4,:Gf4,:Ef4,:Gf4,:F4,:E4,:Ef4,:F4,:E4,:Ef4,:Gf4,:F4,:E4,:Ef4,:Gf4,:F4,:E4,:Ef4,:F4,:E4,:Ef4,:D4,:F4,:E4,:Df4,:C4,:Df4,:Gf4,:A4,:D4,:Gf4,:F4,:D4,:Df4,:Df5,:D4,:F4,:E4,:Df4,:C4,:Df4,:Gf4,:A4,:D4,:Gf4,:F4,:D4,:Df4,:Ef5,:Df5,:B4,:Bf4,:Af4,:Ef4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Df5,:Ef5,:F5,:Ef5,:Df5,:B4,:Bf4,:B4,:Df5,:D5,:Df5,:B4,:Bf4,:B4,:D5,:E5,:D5,:Cs5,:B4,:Bf4,:A4,:Af4,:Gf4,:D4,:Gf4,:Af4,:A4,:Bf4,:Ef5,:Df5,:Ef5,:Df5,:Ef5,:Df5,:Df5,:Bf4,:Gf5,:F5,:Gf5,:F5,:F5,:Bf4,:F5,:Gf5,:Af5,:Bf5,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:Df6,:E6,:D6,:Df6,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Df4,:Gf4,:F4,:E4,:Df4,:A4,:G4,:Df4,:B4,:A4,:G4,:F4,:Ef4,:Ef4,:Df4] b[0]=[1,1.409,0.106,0.102,0.704,0.078,0.091,0.453,0.337,0.286,0.206,1.517,0.203,0.197,4.995,1.21,0.107,0.093,0.569,0.046,0.102,0.366,0.238,0.248,0.228,1.167,0.216,0.164,1.303,0.206,0.125,0.132,0.08,0.109,0.091,0.091,0.267,0.202,1.176,0.199,0.154,1.162,0.186,0.139,0.077,0.078,1.094,0.229,2.191,1.281,2.624,4.332,1.206,0.126,0.086,0.641,0.103,0.093,0.396,0.367,0.184,0.189,0.659,0.113,0.055,0.267,0.084,0.075,0.234,0.164,0.168,0.122,0.115,0.042,0.282,0.149,0.173,1.29,0.289,0.184,0.215,0.125,0.106,0.104,0.094,0.09,0.057,0.244,0.061,0.123,0.863,0.205,0.106,0.106,0.53,0.073,0.071,0.116,0.235,0.084,0.042,0.115,0.399,0.104,0.055,0.058,0.245,0.052,0.27,0.19,1.38,0.489,0.216,0.189,0.045,0.299,0.181,0.208,0.045,0.332,0.327,0.215,0.087,0.338,0.267,0.158,0.071,0.142,0.183,0.364,0.228,0.251,0.65,0.237,0.051,0.266,0.177,1.387,2.544,0.187,0.094,0.145,0.173,0.342,0.226,0.194,0.319,0.155,0.08,0.193,0.173,0.64,0.955,0.147,0.11,0.103,1.576,0.273,0.109,0.122,0.119,0.086,0.197,0.102,0.039,0.109,0.289,0.268,0.372,1.181,0.245,0.102,0.128,0.118,0.118,0.068,0.119,0.058,0.087,0.015,0.044,0.126,0.131,0.068,0.057,0.058,0.1,0.071,0.048,0.048,0.614,0.112,0.086,0.044,0.078,0.06,0.075,0.084,0.254,0.093,0.046,0.094,0.103,0.077,0.203,0.049,0.046,0.052,1.357,0.993,0.096,0.089,0.315,0.065,0.093,0.345,0.263,0.199,0.373,0.787,0.163,0.049,0.319,0.179,1.338,0.109,0.075,0.491,0.089,0.125,0.47,0.472,0.647,1.337,0.21,0.131,0.118,0.125,0.144,0.1,0.428,0.428,0.451,0.805,0.125,0.152,0.109,0.109,0.125,0.107,0.432,0.457,0.673,2.575,0.325,0.081,0.421,0.393,2.241,0.625,0.58,4.407,4.529,0.572,0.441,0.672,1.399,0.283,7.843] # James Galway a[0]=[:r,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:C6,:B5,:Bf5,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Gf4,:G4,:C5,:Gf4,:G4,:Df5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Af4,:B4,:Df5,:E5,:Af5,:Af5,:B5,:Df6,:Ef6,:Bf5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:Af4,:Bf4,:Df5,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Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Df4,:Gf4,:F4,:E4,:Df4,:A4,:G4,:Df4,:B4,:A4,:G4,:F4,:Ef4,:Ef4,:Df4] b[0]=[1,2.337,0.143,0.096,0.789,0.134,0.098,0.6,0.261,0.201,0.19,1.994,0.372,0.281,3.761,1.203,0.123,0.065,0.272,0.102,0.093,0.325,0.19,0.16,0.171,1.203,0.417,0.181,0.836,0.091,0.091,0.145,0.083,0.102,0.367,0.094,0.223,0.198,1.065,0.517,0.23,2.416,0.366,0.138,0.094,0.098,0.923,0.19,2.922,1.673,2.157,4.033,1.092,0.091,0.102,0.232,0.127,0.109,0.555,0.19,0.181,0.189,0.6,0.094,0.089,0.194,0.091,0.085,0.377,0.143,0.134,0.141,0.47,0.083,0.33,0.183,0.225,1.829,0.412,0.412,0.187,0.112,0.114,0.1,0.098,0.414,0.053,0.359,0.145,0.234,1.622,0.379,0.185,0.181,0.595,0.105,0.067,0.127,0.312,0.087,0.145,0.141,0.452,0.149,0.105,0.127,0.321,0.094,0.281,0.274,2.188,0.657,0.457,0.468,0.074,0.39,0.192,0.183,0.04,0.194,0.18,0.176,0.054,0.176,0.196,0.23,0.053,0.221,0.294,0.55,0.386,0.941,1.277,0.463,0.085,0.328,0.321,1.769,2.159,0.526,0.058,0.178,0.283,0.55,0.332,0.557,0.37,0.189,0.051,0.223,0.243,1.339,2.139,0.653,0.23,0.178,2.099,0.317,0.096,0.094,0.074,0.105,0.889,0.134,0.094,0.094,0.423,0.229,0.207,1.696,0.243,0.123,0.141,0.1,0.071,0.089,0.078,0.129,0.087,0.102,0.138,0.143,0.141,0.132,0.098,0.141,0.094,0.096,0.131,1.893,0.196,0.141,0.087,0.077,0.069,0.073,0.076,0.059,0.105,0.058,0.082,0.069,0.076,0.076,0.064,0.066,0.075,0.055,0.074,0.063,0.067,0.06,0.055,0.09,1.364,0.212,0.092,0.093,0.076,0.063,0.073,0.071,0.071,0.067,0.081,0.061,0.08,0.063,0.088,0.087,0.073,0.068,0.076,0.063,0.078,0.066,0.077,0.067,0.086,0.092,0.065,1.498,0.109,0.093,0.136,4.922,1.065,0.1,0.09,0.24,0.089,0.09,0.373,0.229,0.14,0.143,1.53,0.603,0.093,0.744,0.417,1.341,0.096,0.096,0.278,0.094,0.093,0.465,0.323,0.415,0.746,0.455,0.102,0.137,0.129,0.102,0.096,0.37,0.232,0.187,0.561,0.278,0.184,0.098,0.13,0.142,0.096,0.553,0.607,1.021,1.564,0.418,0.055,0.229,0.239,1.848,0.678,0.448,3.482,3.158,0.464,0.514,0.643,2.39,0.536,8.221] # Emmanuel Pahud a[0]=[:r,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf5,:C6,:B5,:Bf5,:Bf5,:A5,:B5,:Af5,:G5,:A5,:Gf5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Gf4,:G4,:C5,:Gf4,:G4,:Df5,:F5,:E5,:Df5,:Bf4,:Gf4,:G4,:B4,:Af4,:B4,:Df5,:E5,:Af5,:Af5,:B5,:Df6,:Ef6,:Bf5,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:F4,:E4,:Df4,:Bf4,:A4,:B4,:Af4,:G4,:A4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Gf5,:F5,:Ef5,:Df5,:Bf4,:Af4,:Df4,:Ef4,:Gf4,:Af4,:Bf4,:Df5,:Ef5,:Gf5,:F5,:Ef5,:Df5,:Bf4,:Df5,:Ef5,:Gf5,:A5,:Af5,:G5,:Gf5,:Ef5,:D5,:Df5,:C5,:A4,:Af4,:G4,:Gf4,:Ef4,:Gf4,:F4,:E4,:Ef4,:F4,:E4,:Ef4,:Gf4,:F4,:E4,:Ef4,:Gf4,:F4,:E4,:Ef4,:F4,:E4,:Ef4,:D4,:F4,:E4,:Df4,:C4,:Df4,:Gf4,:A4,:D4,:Gf4,:F4,:D4,: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227,2.459,0.692,0.422,0.278,0.284,0.184,0.141,0.092,0.133,0.053,0.131,0.094,0.147,1.951,0.424,0.178,0.147,1.014,0.096,0.087,0.097,0.652,0.095,0.088,0.049,1.106,0.103,0.096,0.131,0.694,0.096,0.324,0.424,2.833,0.831,1.026,0.646,0.093,0.451,0.291,0.414,0.051,0.321,0.419,0.587,0.069,0.948,1.855,0.859,0.098,0.371,0.453,0.616,0.6,0.976,1.629,1.018,0.088,0.241,0.376,2.963,3.953,1.061,0.098,0.604,0.359,0.659,0.471,0.88,2.286,0.869,0.092,0.327,0.3,3.049,2.918,0.373,0.139,0.135,1.937,0.392,0.227,0.096,0.1,0.096,0.776,0.135,0.098,0.057,0.514,0.319,0.284,1.894,0.331,0.224,0.296,0.12,0.153,0.224,0.139,0.143,0.229,0.184,0.096,0.229,0.094,0.098,0.129,0.094,0.057,0.082,0.098,1.304,0.184,0.276,0.063,0.078,0.055,0.084,0.055,0.084,0.045,0.043,0.057,0.278,0.929,0.092,0.324,0.104,0.096,0.08,0.051,0.049,0.071,0.063,0.073,0.059,0.059,0.053,0.065,0.057,0.145,1.114,0.324,0.09,0.098,7.888,1.616,0.057,0.092,1.537,0.09,0.094,0.694,0.408,0.382,0.882,1.814,0.455,0.055,0.745,0.416,1.902,0.135,0.1,1.065,0.133,0.102,0.655,0.512,0.835,3.933,0.478,0.229,0.186,0.235,0.178,0.147,0.598,0.416,0.608,1.024,0.504,0.235,0.235,0.229,0.186,0.188,0.741,0.51,0.978,3.222,0.584,0.086,0.524,0.363,3.673,0.927,0.694,6.353,4.145,1.114,0.792,1.298,2.124,0.435,13.131]オープンソースソフトウェアだけで、このようなデータが作成できますので、音楽や演奏の解析等へのSonic Piのさらなる活用が期待されます。
# Random to Melody by Sonic Pi use_random_seed 0 use_debug false use_bpm 180 use_synth :piano low=:C4.to_i high=:C6.to_i # Hey Jude 2 vars a=[:C5,:A4,:A4,:C5,:D5,:G4,:G4,:A4,:Bf4,:F5,:F5,:E5,:C5,:D5,:C5,:Bf4,:A4] b=[1.0,2.5,0.5,0.5,0.5,3.0,0.5,0.5,1.0,1.5,0.5,0.5,0.5,0.5,0.25,0.25,2.0] da=[] s=0 for i in 0...a.length da[i]=(rrand_i(low,high)-a[i].to_i) # da[i]=-12 # 一オクターブ下から始まるメロディーに # da[i]=-a[i].to_i+60 # 全ての音が :C4 から始まるメロディーに play a[i]+da[i], amp:3,sustain:2,release:2 sleep b[i] s+=da[i].abs end puts "Object func=#{s}" while s>0 sleep 2 s=0 for i in 0...a.length r=a[i]+rrand_i(-da[i].abs, da[i].abs); if ( (a[i]-r).abs <= da[i].abs ) then da[i]=(a[i]-r).abs; end play a[i]+da[i], amp:3,sustain:2,release:2 sleep b[i] s+=da[i]; end puts "Object func=#{s}" end
path="/Applications/LibreOffice.app/Contents/share/gallery/sounds/" i=0 loop do sample path,i sleep sample_duration path,i i=i+1 end
s=["apert.wav","apert2.wav","applause.wav","beam.wav","beam2.wav","cow.wav","curve.wav","drama.wav","explos.wav","falling.wav","glasses.wav","gong.wav","horse.wav","kling.wav","kongas.wav","laser.wav","left.wav","nature1.wav","nature2.wav","ok.wav","pluck.wav","roll.wav","romans.wav","soft.wav","space.wav","space2.wav","space3.wav","sparcle.wav","strom.wav","theetone.wav","top.wav","train.wav","untie.wav","ups.wav","wallewal.wav"] path="/Applications/LibreOffice.app/Contents/share/gallery/sounds/" for i in 0...s.length sample path+s[i] sleep sample_duration path+s[i] sleep 0.1 end
use_debug false use_random_seed Time.new.usec set_cent_tuning! ( hz_to_midi(440) - note(:A4) )*100 # チューニングの変更 440を442にしたい場合は、hz_to_midi(440)の数値を変更ください。 n=5 # 鳴らす音の数 d=0.2 # 音をずらす量 半音=1, 0.2は20セント key=rrand_i(:C3.to_i,:C5.to_i) # 音程を決める乱数 範囲はC3からC5。 :C3.to_iを:C4.to_iとすると中央のドからの1オクターブ間に変更できます。 r=rrand_i(1,n) # ずらされる音を何番目にするかを決める乱数 ud=([-1,1].choose) # 上にずらすor下にずらすかを決める乱数 d=d*ud for i in 1..n dkey=0 dkey=d if i==r play key+dkey,sustain:0.5,release:1 # sustainの値で音の長さを変更できます。 sleep 1.5 # 上の行で与えた長さに応じた音の間隔を与えます end hz0=midi_to_hz(key) hz1=midi_to_hz(key+d) note_info_string = note_info(key).to_s note_name_match = note_info_string.match(/:\w+\d+/) noteName=note_name_match[0][1..-1].to_sym puts "Ans.= #{r}番目 音程= #{noteName} ズレ(cent)= #{d} 周波数差(Hz)= #{(hz1-hz0).round(2)}"
use_bpm 240 use_synth :prophet use_random_seed Time.new.usec n1=rrand_i(48,72) n2=n1 loop do while n1==n2 n2=rrand_i(48,72) end dn=n2-n1 puts n1,n2,dn s=play n1, sustain: dn.abs, note_slide: dn.abs, attack:0, release:0 control s,note:n2 sleep dn.abs n1=n2 end
ここから def fastfloor(x) (x > 0 ? x : x-1).to_i end def noise(x, y, z) # find unit cube that contains point x_ = fastfloor(x) & 255 y_ = fastfloor(y) & 255 z_ = fastfloor(z) & 255 # find relative x,y,z of point in cube x -= fastfloor(x) y -= fastfloor(y) z -= fastfloor(z) # compute fade curves for each of x,y,z u, v, w = fade(x), fade(y), fade(z) # hash coordinates of the 8 cube corners a = PT[x_] + y_ aa = PT[a] + z_ ab = PT[a+1] + z_ b = PT[x_+1] + y_ ba = PT[b] + z_ bb = PT[b+1] + z_ # and add blended results from 8 corners of cube lerp(w, lerp(v, lerp(u, grad(PT[aa ], x , y , z ), grad(PT[ba ], x-1, y , z )), lerp(u, grad(PT[ab ], x , y-1, z ), grad(PT[bb ], x-1, y-1, z ))), lerp(v, lerp(u, grad(PT[aa+1], x , y , z-1), grad(PT[ba+1], x-1, y , z-1)), lerp(u, grad(PT[ab+1], x , y-1, z-1), grad(PT[bb+1], x-1, y-1, z-1))) ); end def fade(t); t * t * t * (t * (t * 6 - 15) + 10); end def lerp(t,a,b); a + t * (b - a); end def grad(_hash, x, y, z) h = _hash & 15 u = h<8 ? x : y v = h<4 ? y : ((h==12 || h==14) ? x : y) ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v) end PT_PERM =[ 151,160,137,91,90,15, 131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23, 190, 6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33, 88,237,149,56,87,174,20,125,136,171,168, 68,175,74,165,71,134,139,48,27,166, 77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244, 102,143,54, 65,25,63,161, 1,216,80,73,209,76,132,187,208, 89,18,169,200,196, 135,130,116,188,159,86,164,100,109,198,173,186, 3,64,52,217,226,250,124,123, 5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42, 223,183,170,213,119,248,152, 2,44,154,163, 70,221,153,101,155,167, 43,172,9, 129,22,39,253, 19,98,108,110,79,113,224,232,178,185, 112,104,218,246,97,228, 251,34,242,193,238,210,144,12,191,179,162,241, 81,51,145,235,249,14,239,107, 49,192,214, 31,181,199,106,157,184, 84,204,176,115,121,50,45,127, 4,150,254, 138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180 ] PT = []; (0...256).each { |i| PT[256+i] = PT_PERM[i]; PT[i] = PT_PERM[i] } # 以上がPerlin Noise関数の定義部分で、いじらずにそのまま用います。 # 以下が演奏部分で、関数にパラメータを与えてから乱数値を得て、playしています。 use_random_seed Time.new.usec # <<<<< use_synth :piano x=rand # <<<<< inc=0.015 * 3 # <<<<< loop do a=(noise x+inc, x, 0.0 )* 20 # <<<<< a=-60 if a<-60 puts a play 60+a.to_i, sustain:1 sleep 0.1 x=x+inc end
use_debug false define :fun do |x| return x**3 -3*x**2 +x +3 # Equation end loop do x=rrand(-1,1) # initial value lop=0 f=fun x while f.abs>0.00001 # Convergence criterion lop=lop+1 x1=x*1.001 f1=fun x1 df=(f-f1)/(x-x1) x=x-f/df f=fun x play 60+x*5 if 60+x*5 >0 puts "Loop= #{lop}, x= #{x}, ObjectFunc= #{f}" sleep 0.25 sample :drum_cymbal_closed sleep 0.25 if lop>100 then puts "##### Diverged ##########" synth :square,note: :C3,sustain:2 sleep 3 break end end if f.abs<=0.00001 sample :drum_cymbal_hard,amp:3 puts "----- Converged ----------" puts "Loop= #{lop}, x= #{x}, ObjectFunc= #{f}" sleep 1 end end
# SonicPiによる将棋の棋譜ファイルの演奏 # Shogi game record music by Sonic Pi, 2018.4.1 Hiroshi Tachibana # 棋譜データを読み込み、駒の動きを音にします。 # Sonic Piのログ表示領域を適当なサイズにしておくと、棋譜をテキストとして、盤面が静止した状態で観察しながら音を聞くことができます。 # 棋譜には、"CSA標準ファイル形式"を用います。(半角英数だけで表示できて簡便なのを利点と考えて採用) # http://www.computer-shogi.org/protocol/record_v22.html # 将棋盤は、右上が一1、左下が九9 # 一手の前後の動きのXY座標をそれぞれ、座標変化をポルタメントで変化させた2つの音として同時に鳴らし、先手の音を左側(pan:-1)、後手の音を右側(pan:1)としています。 # 駒の種類によってsynthの音色を変えています。成駒にはディストーションをかけました。 # 相手の駒を取った場合と駒台から打った場合には、特に別の音も鳴らしています。 # CSA規格中、盤面座標の数字は移動前と移動後の4桁連続のみ場合しか扱っていません。 # 対局データの開始は、先頭文字が%でなくなった時にしています。 # 最終行の判定は、先頭文字の+-が、%になった時にしており、途中に%行があるとそこで停止してしまいます。 # 棋譜ファイルの形式は CSA標準で、将棋DB2 https://shogidb2.com/ 等から入手できる。 # 棋譜表示画面の左下の [棋譜の書き出し]->[CSA形式] で表示し、コピーして保存する. path="藤井聡太 四段 vs. 佐藤天彦 名人 第11回朝日杯将棋オープン戦本戦.csa" #path="藤井聡太 五段 vs. 羽生善治 竜王 第11回朝日杯将棋オープン戦準決勝.csa" #path="藤井聡太 六段 vs. 杉本昌隆 七段 第68期王将戦一次予選.csa" #path="Ponanza_佐藤名人.txt" use_bpm 80 # 速度の設定 use_debug false # 9×9の2次元配列の作成。各要素はスペース3つ" " ban=Array.new(9," ") ban.length.times{|i| ban[i]=Array.new(9," ") } #XY=[:C4,:D4,:E4,:G4,:A4,:C5,:D5,:E5,:G5] # XY座標の音程 XY=[:E3,:G3,:C4,:E4,:G4,:C5,:E5,:G5,:C6] # XY座標の音程 komaS=["FU","TO","KY","NY","KE","NK","GI","NG","KI","KA","UM","HI","RY","OU"] # 駒の種類による音色、成り駒には、distortionをかける komaSound=[:beep,:beep, # 歩 FU,NF :blade,:blade, # 香車 KY,NY :chipbass,:chipbass,# 桂馬 KE,NK :tri,:tri, # 銀 GI,NG :square, # 金 KI :mod_tri,:mod_tri, # 角 KA,UM :mod_saw,:mod_saw, # 飛車 HI,RY :zawa] # 王 OU d=[] open(path){|f| d = f.readlines} i=0 while(d[i].slice(0,1) != "+") # 駒の初期配置を棋譜から読み込む。+で先手の手が始まる前までのPで始まる9行。 if d[i].slice(0,1)=="P" then # 行の先頭がP k=d[i].slice(1,1).to_i-1 ban[8][k]=d[i].slice(2,3) ban[7][k]=d[i].slice(5,3) ban[6][k]=d[i].slice(8,3) ban[5][k]=d[i].slice(11,3) ban[4][k]=d[i].slice(14,3) ban[3][k]=d[i].slice(17,3) ban[2][k]=d[i].slice(20,3) ban[1][k]=d[i].slice(23,3) ban[0][k]=d[i].slice(26,3) # 駒の初期配置の表示 # puts k+1,ban[8][k], ban[7][k] ,ban[6][k] ,ban[5][k] ,ban[4][k] ,ban[3][k] ,ban[2][k] ,ban[1][k] ,ban[0][k] end i=i+1 end puts # 駒のない位置は、スペースとする for ii in 0..8 for jj in 0..8 ban[ii][jj]=" " if ban[ii][jj]==" * " end end # 駒の全体配置を表示する puts 0 # 手数 for ii in 0..8 puts ban[8][ii],ban[7][ii] ,ban[6][ii] ,ban[5][ii] ,ban[4][ii] ,ban[3][ii] ,ban[2][ii] ,ban[1][ii] ,ban[0][ii] end #ファイル中の位置jを先手の初手の位置に移動する。 j=i+1 while(d[j].slice(0,1) != "%") # puts j-i,d[j] # 手数、棋譜での表記 sente=true if d[j].slice(0,1)=="+" # +で始まる行が先手の手 sente=false if d[j].slice(0,1)=="-" # -で始まる行が後手の手 pos1=d[j].slice(1,2) # 移動前の位置 pos2=d[j].slice(3,2) # 移動後の位置 koma=d[j].slice(5,2) # 移動後の駒(成っている場合もある) # 駒の音色 km=99 for k in 0...komaS.length if ban[pos1.slice(0,1).to_i-1][pos1.slice(1,1).to_i-1].slice(1,2) == komaS[k] then km=k # puts "===",ban[pos1.slice(0,1).to_i-1][pos1.slice(1,1).to_i-1].slice(1,2),komaS[k],km,k end end sleep 0.5 panVal=-1 if sente # 先手の音を左側から出すためのpan panVal=1 if !sente # 後手の音を右側から出すためのpan use_synth komaSound[km] # 成り駒の場合は、distortionをかける # 駒台からの打駒の場合 if(pos1.slice(0,1).to_i-1==-1) then play :C7,amp:2 play :C3,amp:3 sleep 0.2 # 通常の駒の移動の場合 else # 成駒の場合 if(km==1 || km==3 || km==5 || km==7 || km==10 || km==12) then with_fx :distortion,distort:0.9 do x=play XY[pos1.slice(0,1).to_i-1],pan:panVal,note_slide:0.75,sustain:1 # 移動前のX座標の音 y=play XY[pos1.slice(1,1).to_i-1],pan:panVal,note_slide:0.75,sustain:1 # 移動前のY座標の音 sleep 0.25 control x,note:XY[pos2.slice(0,1).to_i-1],pan:panVal # 移動後のX座標の音 control y,note:XY[pos2.slice(1,1).to_i-1],pan:panVal # 移動後のY座標の音 sleep 0.25 end else # 成っていない駒の場合 x=play XY[pos1.slice(0,1).to_i-1],pan:panVal,note_slide:0.75,sustain:1 # 移動前のX座標の音 y=play XY[pos1.slice(1,1).to_i-1],pan:panVal,note_slide:0.75,sustain:1 # 移動前のY座標の音 sleep 0.25 control x,note:XY[pos2.slice(0,1).to_i-1],pan:panVal # 移動後のX座標の音 control y,note:XY[pos2.slice(1,1).to_i-1],pan:panVal # 移動後のY座標の音 sleep 0.25 end end # 相手の駒を取った場合(移動後の場所が最初から空でなかった場合)高音とドラムを鳴らす if ban[pos2.slice(0,1).to_i-1][pos2.slice(1,1).to_i-1] !=" " then use_synth :dpulse (play 84,pan:panVal; sample :drum_snare_hard,pan:panVal) if sente (play 96,pan:panVal; sample :drum_cymbal_hard,pan:panVal) if !sente # sleep 0.2 end # 打駒の場合 if pos1=="00" then ban[pos2.slice(0,1).to_i-1][pos2.slice(1,1).to_i-1]="+"+koma if sente # 打駒の場合、先手では先頭に+をつけて駒を移動後の場所に ban[pos2.slice(0,1).to_i-1][pos2.slice(1,1).to_i-1]="-"+koma if !sente# 打駒の場合、後手では先頭に-をつけて駒を移動後の場所に else ban[pos2.slice(0,1).to_i-1][pos2.slice(1,1).to_i-1]="+"+koma if sente # 打駒でない場合、駒を移動後の場所に ban[pos2.slice(0,1).to_i-1][pos2.slice(1,1).to_i-1]="-"+koma if !sente # 打駒でない場合、駒を移動後の場所に end ban[pos1.slice(0,1).to_i-1][pos1.slice(1,1).to_i-1]=" " if pos1!="00" # 打駒でない場合には、移動元の場所は空にする。 # 駒の全体配置を再表示する puts j-i,d[j] # 手数、棋譜での表記 for k in 0..8 puts ban[8][k],ban[7][k] ,ban[6][k] ,ban[5][k] ,ban[4][k] ,ban[3][k] ,ban[2][k] ,ban[1][k] ,ban[0][k] #puts ban[0][k],ban[1][k] ,ban[2][k] ,ban[3][k] ,ban[4][k] ,ban[5][k] ,ban[6][k] ,ban[7][k] ,ban[8][k] end j=j+1 end
in_thread do 6.times do sample :drum_cymbal_closed sleep 1 end end use_synth :beep x = play 60, sustain: 5, note_slide:3 use_synth :saw y = play 72, sustain: 5, note_slide:1 sleep 1 control x, note:72 sleep 1 control y, note:60 sleep 3
path="/各PCでのパス/李世石-AlphaGo-20160315.sgf" # 棋譜ファイルをpath=の後ろにドロップすれば、入力されます。 #path="/各PCでのパス/AlphaGo-柯潔-20170527.sgf" use_bpm 160 # 速度 use_debug false scaleName=:hirajoshi #与えるスケール (平調子) :kumoi :iwato :egyptian :bartok など変更可 # 19×19の2次元配列の作成。 SGFファイルでは、1-19は、a-sと表される.左上が原点 ban=Array.new(19," ") ban.length.times{|i| ban[i]=Array.new(19," ") } for i in 0...19 for j in 0...19 ban[i][j]="." ban[i][j]="o" if (i==3 || i==9 || i==15) && (j==3 || j==9 || j==15) # 盤上の9箇所の黒点の位置 end end te=0 # 手数表示用変数 # 初期盤面の表示 puts te for i in 0...19 ban1L="" for j in 0...19 ban1L=ban1L+ban[i][j]+" " end puts ban1L end # BGM の Ocean Waves( copied from https://sonic-pi.net/ ) in_thread do with_fx :reverb, mix: 0.5 do 100.times do s = synth [:bnoise, :cnoise, :gnoise].choose, amp: rrand(0.1, 0.3), attack: rrand(0, 4), sustain: rrand(0, 2), release: rrand(1, 3), cutoff_slide: rrand(0, 3), cutoff: rrand(60, 80), pan: rrand(-1, 1), pan_slide: 1 control s, pan: rrand(-1, 1), cutoff: rrand(60, 115) sleep rrand(2, 3) end end end f=File.open(path).read # pathで指定された外部棋譜ファイルを開く for i in 0...f.length # データの文字の順番が、;、BまたはW、[、2文字開けて]となった場合に手とみなします。 if f.slice(i, 1)==";" && (f.slice(i+1, 1)=="B" || f.slice(i+1, 1)=="W") && f.slice(i+2, 1)=="[" && f.slice(i+5, 1)=="]" then x=f.slice(i+3, 1).ord-97 # ASCII文字を数値に aは97 y=f.slice(i+4, 1).ord-97 # ASCII文字を数値に # 先手Blackの場合の盤面文字の設定と音 pan:-1 if f.slice(i+1, 1)=="B" then ban[y][x]="C" use_synth :piano # 音色の指定B # scaleNameで指定されたの音階に従って鳴らす.(音階によって1オクターブ内の音数の多少(3-12)があるため、開始音を上下する必要あり) play scale(:C3, scaleName, num_octaves: 7)[x],pan: -1,sustain:1 # C3で始まる7オクターブのscaleの中からx番目の音を取り出して鳴らす. sleep 0.2 # X座標の音を鳴らした後、Y座標を鳴らすまでの遅れ時間 use_synth :pluck # 音色の指定B play scale(:C3, scaleName, num_octaves: 7)[y],pan: -1,sustain:1 sleep 0.8 # 上記の遅れ時間と合わせて1.0拍になるようにしています。 end # 後手Whiteの場合の盤面文字の設定と音 pan:1 if f.slice(i+1, 1)=="W" then ban[y][x]="0" use_synth :piano # 音色の指定W play scale(:C3, scaleName, num_octaves: 7)[x],pan: 1,sustain:1 sleep 0.2 # X座標の音を鳴らした後、Y座標を鳴らすまでの遅れ時間 use_synth :pluck # 音色の指定W play scale(:C3, scaleName, num_octaves: 7)[y],pan: 1,sustain:1 sleep 0.8 # 上記の遅れ時間と合わせて1.0拍になるようにしています。 end # 盤面の描画 te=te+1 puts te,f.slice(i+1, 1)+f.slice(i+3, 2) for i in 0...19 ban1L="" for j in 0...19 ban1L=ban1L+ban[i][j]+" " end puts ban1L end else sleep 0.001 # データを読み飛ばす場合 end end==========
use_synth :pluck arpeggio=(ring 0,1,2,1,3,2,1,2) # Intro c=[:G3,:M,:G3,:M,:E3,:m,:E3,:m,:A3,:m,:A3,:m,:B3,:m,:B3,'7', :C4,:M,:C4,:M,:A3,:m,:A3,:m,:D4,:M,:C4,:M,:G3,:M] #,:G3,:M] with_fx :reverb, room:0.9 do for i in 0...c.length/2 8.times do play chord(c[i*2],c[i*2+1],num_octaves:2)[arpeggio.tick] sleep 0.25 end end play :G3 end
# Arpeggios with overlapping sounds p1=[0,3,1,3] # pattern1 p2=[0,[1,2,3],[0,4],5] # pattern2 c1=chord(:C4,:M,num_octaves:2) # chord1 c2=chord(:G4,:M,num_octaves:2) # chord2 c3=chord(:A3,:m,num_octaves:2) # chord3 c4=chord(:F4,:M,num_octaves:2) # chord4 define :playChord do |c,p,s| p.each do |pp| if pp.instance_of?(Array) then # 要素が配列だった場合は、さらに1音づつ鳴らす. pp.each do |s| play c[s],amp:0.5 end else play c[pp],amp:0.5 end sleep s end end loop do playChord c1,p1,0.25 playChord c1,p2,0.25 playChord c2,p1,0.25 playChord c2,p2,0.25 playChord c3,p1,0.25 playChord c3,p2,0.25 playChord c4,p1,0.25 playChord c4,p2,0.25 end
# TAB to #SonicPi, Eagles Hotel California intro. tuning=[:E3,:A3,:D4,:G4,:B4,:E5] x=999 a=[ # Bm [7,9,9,7,7,7],8, [x,x,9,x,x,x],16, [x,x,x,7,x,x],16, [x,x,9,x,x,x],16, [x,x,x,x,7,x],16, [x,x,9,x,x,x],16, [x,x,x,7,x,x],16, [x,x,x,x,x,7],4, [x,x,x,7,x,x],8, [x,x,x,9,7,x],8, # F#7 [x,x,8,x,x,x],8, [x,x,x,9,x,x],16, [x,x,x,x,7,x],16, [x,9,x,x,x,x],16, [x,x,x,x,x,9],16, [x,x,x,9,x,x],16, [x,x,x,x,7,x],16, [x,x,8,x,x,x],2, # Asus2 [x,x,7,x,x,x],8, [x,x,x,9,x,x],16, [x,x,x,x,10,x],16, [x,x,x,x,10,x],16, [x,x,x,x,x,7],8, [x,x,x,x,10,x],16, [x,x,7,x,x,x],8, [x,x,x,9,x,x],16, [x,x,x,x,10,x],16, [x,7,x,x,x,x],8, [x,x,x,9,x,x],16, [x,x,x,x,7,x],16, # E9 [x,11,x,x,x,x],8, [x,x,x,x,x,7],16, [x,x,x,7,x,x],16, [x,x,x,x,x,7],16, [x,x,x,x,7,x],16, [x,x,x,7,x,x],16, [x,x,12,x,x,x],16, [x,x,x,x,x,7],2, # G [x,10,x,x,x,x],8, [x,x,9,x,x,x],16, [x,x,x,7,x,x],16, [x,x,9,x,x,x],16, [x,x,x,x,8,x],16, [x,x,9,x,x,x],16, [x,x,x,7,x,x],16, [x,x,x,x,x,7],8, [x,10,x,x,x,x],16, [x,x,x,x,8,x],16, [x,x,x,7,x,x],16, [x,x,x,9,x,x],16, [x,x,x,x,7,x],16, [x,x,x,9,x,x],16, # D [x,x,7,x,x,x],8, [x,x,x,x,x,10],16, [x,x,x,x,7,x],16, [x,x,x,7,x,x],16, [x,x,x,x,x,10],16, [x,x,7,x,x,x],16, [x,x,x,x,7,x],16, [x,9,x,x,x,x],8, [x,x,x,x,x,10],16, [x,x,x,x,7,x],16, [10,9,x,x,x,x],8, [x,x,7,x,x,x],16, [x,x,x,x,7,x],16, # Em7 [x,7,x,x,x,x],16, [x,x,x,x,8,x],16, [x,x,9,x,x,x],16, [x,x,x,7,x,x],16, [x,x,9,x,x,x],16, [x,x,x,x,8,x],16, [x,x,9,x,x,x],16, [x,x,x,x,8,x],16, [x,x,x,x,x,7],8, [x,x,9,x,x,x],16, [x,x,x,7,x,x],16, [7,x,x,x,x,x],16, [x,x,9,x,x,x],16, [x,x,9,x,x,x],16, [x,x,x,x,7,x],16, # F#7 [x,9,x,x,x,x],8, [x,x,8,x,x,x],16, [x,x,x,9,x,x],16, [x,x,x,9,x,x],16, [x,x,x,x,7,x],16, [x,x,8,x,x,x],16, [x,x,x,9,x,x],16, [x,x,x,x,x,9],2 ] use_bpm 74 use_synth :pluck with_fx :reverb,room:0.9 do for i in 0...a.length/2 for j in 0...6 play tuning[j]+a[i*2][j] if a[i*2][j] !=x end sleep 4.0/a[i*2+1] end end
#SonicPi Easier way to play ASCII tab sheet music. # Led Zeppelin, Stairway to heaven, Intro. t=[ "e-------5-7-----7-8-----8-2-----2-0---------0---------------------", "b-----5-----5-------5-------3-------1---1-----1-------------------", "g---5---------5-------5-------2-------2---------2-0-2-2-----------", "d-7-------6-------5-------4-------3-------------------------------", "a-------------------------------------------------2-0-0---0--/8-7-", "e-----------------------------------------------------------------", "e-------5-7-----7-8-----8-2-----2-0---------0---------------------", "b-----5-----5-------5-------3-------1---1-----1-------------------", "g---5---------5-------5-------2-------2---------2-0-2-2-----------", "d-7-------6-------5-------4-------3-------------------------------", "a-------------------------------------------------2-0-0-------0-2-", "e-----------------------------------------------------------------", "e-------0-2-----2-0-----0-----------------3-----3-3h2-2-2---------", "b-----------3-------1-----1-------1-----1---0-----------3---------", "g-----0-------2-------2-----2-------0---------0-------------------", "d---2-----0-------3-------------------2-----------0-----0---------", "a-3-----------------------0---0-2-3---------------------------0-2-", "e-----------------------------------------3-----------------------", "e-------0-2-----2-0-----0-----------------------2-0-0-0-----------", "b-----------3-------1-----1-------------1-----3---1-1-1-----------", "g-----0-------2-------2-----2---------0-----2-----2-2-2-----------", "d---2-----0-------3-----------------2-----0-------3-3-3-----------", "a-3-----------------------0---0-2-3-------------------------------", "e-----------------------------------------------------------------" #データの最後の行には , を入れないこと. ] tuning=[:E3,:A3,:D4,:G4,:B4,:E5].reverse for i in 0...t.length/6 for j in 1...t[i*6].length for k in 0...6 case t[i*6+k][j] when "0","1","2","3","4","5","6","7","8","9" play tuning[k]+t[i*6+k][j].to_i end end sleep 0.15 end end
t0= "e-------5-7-----7-8-----8-2-----2-0---------0--------------------- b-----5-----5-------5-------3-------1---1-----1------------------- g---5---------5-------5-------2-------2---------2-0-2-2----------- d-7-------6-------5-------4-------3------------------------------- a-------------------------------------------------2-0-0---0--/8-7- e-----------------------------------------------------------------" t=t0.split("\n").reject(&:empty?) tuning=[:E3,:A3,:D4,:G4,:B4,:E5].reverse for i in 0...t.length/6 for j in 1...t[i].length for k in 0...6 case t[i*6+k][j] when "0","1","2","3","4","5","6","7","8","9" play tuning[k]+t[i*6+k][j].to_i end end sleep 0.15 end end
#SonicPi Sun Light Spectrum Sounds #Spectrum csv data http://rredc.nrel.gov/solar/spectra/am1.5/ASTMG173/compressed/ASTMG173.zip path=" path to ASTMG173.csv" use_debug false use_random_seed Time.new.usec d=[];x=[];y1=[];y2=[];y3=[] open(path){|f| d = f.readlines} puts d.length,"data" for i in 2...d.length x[i]=d[i].chomp.split("\t")[0].to_f y1[i]=d[i].chomp.split("\t")[1].to_f # AM0 spectrum y2[i]=d[i].chomp.split("\t")[2].to_f # AM1 spectrum y3[i]=d[i].chomp.split("\t")[3].to_f # AM1.5 spectrum end for i in (2...d.length).step(1) play hz_to_midi(x[i]*1),amp:(y1[i]+0.1)*0.25,sustain:20,pan:rrand(-1,1) sleep rrand(0.005,0.01) end sleep 20 for i in (2...d.length).step(1) play hz_to_midi(x[i]*1),amp:(y2[i]+0.1)*0.25,sustain:20,pan:rrand(-1,1) sleep rrand(0.005,0.01) end sleep 20 for i in (2...d.length).step(1) play hz_to_midi(x[i]*1),amp:(y3[i]+0.1)*0.25,sustain:20,pan:rrand(-1,1) sleep rrand(0.005,0.01) end sleep 20
use_tuning :just s = play [:C4,:E4,:G4], sustain: 6, note_slide: 0.5 # ドミソ sleep 1 control s, note: [:C4,:F4,:A4] # ドファラ sleep 1 control s, note: [:C4,:E4,:G4] # ドミソ sleep 1 control s, note: [:B3,:D4,:G4] # シレソ sleep 1 control s, note: [:C4,:E4,:G4] # ドミソ sleep 1
use_random_seed Time.new.usec use_synth :dsaw f1=20.0 f2=200.0 DN=[] n=4 slideT=2 totalT=n*slideT*3 for j in 0..n DN[j]=[:F6,:D6,:A5,:D5,:A4,:D4,:A3,:D3,:A2,:D2,:D1] end for i in 0...DN[n].length DN[0][i]= hz_to_midi(rrand(f1,f2)) end for j in 1...n for i in 0...DN[n].length DN[j][i]= DN[0][i]+(DN[n][i]-DN[0][i])/n.to_f+rrand(-n*2+j*2,n*2-j*2) end end with_fx :reverb ,room:1, mix:1 do ##### s = play DN[0], sustain: totalT, note_slide: slideT,amp: 0.1, amp_slide: slideT sleep slideT for i in 1..n control s, note: DN[i],amp: (i/n.to_r)+0.5 sleep slideT end end #####
PP2016mac=["applause.wav","breeze.wav","chimes.wav","drumroll.wav","laser.wav", "type.wav","wind.wav","arrow.wav","camera.wav","click.wav", "explode.wav","push.wav","voltage.wav","bomb.wav","cashreg.wav", "coin.wav","hammer.wav","suction.wav","whoosh.wav"] path="/Applications/Microsoft PowerPoint.app/Contents/Resources/Sounds/" PP2016mac.each do |s| sample path+s sleep sample_duration path+s sleep 0.2 end
# Usage of 1026 samples of MuseScore Drumline Extentions on Sonic Pi path="~/Documents/MuseScore2/拡張機能/mdl/1.1/sfzs/MDL_samples/**" #path="~/Documents/MuseScore2/Extensions/mdl/1.1/sfzs/MDL_samples/**" # for Eng. for i in 0...1026 puts i sample path,i sleep 0.1 end
loop do system("say Hello World") sleep 2 endシステムの声がインストールされていれば、-vで声を指定して、
a=[5,4,3,2,1,0] in_thread do for i in 0..a.length-2 do sample :drum_heavy_kick,amp:1 sample :drum_roll,sustain:1,release:0.1,amp:6-a[i] sleep 1 end sample :drum_bass_hard,amp:10 end for i in a system("say -v Agnes "+i.to_s) sleep 1 end
use_debug false Rules=[1,2,3,6,7,8,10,16,30,54,60,62,90,94,102,110,122,126,150,158,182,188,190,220,222,250] data0="0001000"; # 初期値. 長さや値は任意 def c3(s,i) # 文字列sから位置iを中心に並んだ3文字を取り出す関数の定義 if i==0 then return s[-1,1] +s[i,2] # 先頭の場合、最後の文字を最初にもってくる. elsif i==s.length()-1 then return s[i-1,2] +s[0,1] # 末尾の場合、先頭の文字を後ろにつける. else return s[i-1,3] # 前後を含め3文字を取り出す end end system("say Elementary Cellular Automaton Sounds") sleep 4 pattern=[]; for i in 0...8 pattern[i]="%03b" % i; end for Rule in Rules n=data0.length() RuleB="%08b" % Rule nR=RuleB.length() RuleB=RuleB.reverse # 文字列を逆順にする RBA=RuleB.split(//) # 各文字を要素とする配列に変換する puts "Rule=",Rule puts pattern; puts RBA dataA=[]; # old dataB=[]; # new dataA=data0.split(//); #文字列を1文字づつ配列に格納する puts data0; sleep 0.5 system("say Rule "+Rule.to_s) # macOSのみ sleep 1 if Rule<100 sleep 1.5 if Rule>=100 for k in 0...8 for i in 0...n for j in 0...nR r=dataA.join if c3(r, i) == pattern[j] then dataB[i]=RBA[j] end end end puts dataB.join for i in 0...n play (scale :C4, :hirajoshi, num_octaves:9)[i] if dataA[i]=="1" sleep 0.01 dataA[i]=dataB[i] # dataA=dataB は不可。ポインタ渡しとなる?? end sleep 0.5 end end sleep 1 system("say The end") # macOSのみ
keyNote=:C4 # 元の音 harmonics=[1,2,3,4,5,6,7,8,9,10] # 倍音構成を整数次とする場合 #harmonics=[1,3,5,7,9,11] # 倍音構成を奇数次とする場合 #harmonics=[1,2,4,6,8,10] # (偶数次) hLen=4 # 1つの音を延ばす拍数 hVol=[] for i in 0...harmonics.length hVol[i]= 1.0/harmonics[i] # 倍音の強度 end f0=midi_to_hz(keyNote) len=(harmonics.length+1)*hLen in_thread do play hz_to_midi(f0*harmonics[0]),sustain:len,amp:hVol[0] sleep hLen h=[] for i in 1...harmonics.length h[i]= play hz_to_midi(f0*harmonics[i]),sustain:len-i*hLen,amp:0,amp_slide:hLen control h[i], amp: hVol[i] sleep hLen end end # bell & voice in_thread do for k in 0...harmonics.length sample :perc_bell,amp:0.8,pan:1 case harmonics[k] when 1 sp="1st" when 2 sp="2nd" when 3 sp="3rd" else sp=harmonics[k].to_s+"th" end system("say -v Ava "+sp) # "say -v Agnes " # macOS sleep hLen end endプログラムを実行した音(サイン波部分のみ)をAudacityでスペクトル表示した例
require 'benchmark' puts Benchmark.measure{ sleep 60 } 4回実行すると、(real:実経過時間 , stime:System CPU time , utime:User CPU time) real=59.97406787890941 , stime=0.0028529999999999944, utime=0.0065509999999999735 real=59.98809501528740 , stime=0.00644499999999992 , utime=0.007249999999999979 real=59.98878446593881 , stime=0.005198999999999954 , utime=0.007164999999999644 real=59.98979557584971 , stime=0.004953000000000096 , utime=0.007125999999999966 となりrealは、60秒を少しだけ下回っていました。(ゼロであった子プロセス時間のcstime,cutimeは省略) 3つの値の和でも、 59.98347188 60.00179002 60.00114847 60.00187458 というばらつきがありました。
require 'benchmark' puts Benchmark.measure{ for i in 0...100 sleep 0.1 end } では、 Sonic Piの出力は、{run: 1, time: 10.0}でしたが、 real=9.980002644471824 stime=0.004908999999999997 utime=0.021179000000000003 でした。和は、10.00609064 音楽での時間精度は、この程度で問題ないことと思われます。 波長の半分だけずらした2つの音を同時に鳴らすことによって音を消すというようなことができない時間精度だということがわかります。 # stimeとutimeはrealに含まれている時間かもしれません.
a=[] live_loop :drum1 do use_real_time a=sync "/osc/C" # 楽器をCとしているので puts a sample :drum_snare_soft # 確認のため end配列の a[] から、[1, 10, 15, 3]が得られます。
# permutation music use_debug false S= scale :C4,:major_pentatonic,num_octaves:9 N=4 # 8 or 9 is limit. V=range(0,N) P=[] i=0 V.permutation do |x| P[i]=x i=i+1 end puts P.length for i in 0...P.length spark(P[i]) for j in 0...N play S[P[i][j]] sleep 0.2 end sleep 0.2 end
f="DTMF_04_800.wav" for i in 0...14 do sample f, onset: i sleep 0.3 end
# "Nose Flute Phase" , Inspired by Steve Reich - Reed Phase f="20111015_220614NoseFlutePhase1.wav" lenf=sample_duration f with_fx :reverb,room:0.8,mix:0.5 do i=0 in_thread do 114.times do sample f,pan:0 sleep lenf i=i+1 puts i end end sleep lenf*4 in_thread do 100.times do sample f,pan:-0.7 sleep lenf+0.01 sleep 0.01 end end sleep lenf*8 in_thread do 100.times do sample f,pan:0.7 sleep lenf+0.02 end end end
ド=:C4 play ド sleep 1 和音1=chord(:C4,:M) play 和音1
a10=1234567890123456789012345678901234567890123456789012345678901234567890 #b12=a10.to_s(12).ring # 12音階の場合 b12=a10.to_s(6).ring # 6音階の場合 c3=a10.to_s(3).ring i=0 use_synth :pluck with_fx :reverb, room:1 do in_thread do loop do # play (scale :C, :chromatic)[b12[i].to_i(10)],amp:1.5 # 12音階の場合 play (scale :C, :hirajoshi)[b12[i].to_i(10)],amp:1.5 # 6音階の琴の平調子場合 sleep 0.24 if i % 2 ==1 sleep 0.76 if i % 2 ==0 i=i+1 end end end in_thread do loop do sample :drum_cymbal_closed if c3[i].to_i(12)==0 sample :drum_bass_hard if c3[i].to_i(12)==1 sample :drum_snare_soft if c3[i].to_i(12)==2 sleep 0.5 end end
path="./lenna_simple.svg" # linedrawで変換生成したSVGファイルへのパス f=File.open(path).read use_debug false d = [] dt=0.05 # 折れ線の一つの直線を鳴らす時間 MidiMin=:C3.to_i # 最低音 MidiMax=:C7.to_i # 最高音 Xmin=10000 Xmax=-10000 Ymin=10000 Ymax=-10000 open(path){|f| d = f.readlines} # 座標の最大値、最小値を見つける for i in 0...d.length-1 s0=d[i].index("<polyline points=")+19-1 s1=d[i].index("stroke")-3 s=d[i][s0..s1] d[i]=s.split(",") for j in 0...d[i].length/2 t0=d[i][j*2].to_f t1=d[i][j*2+1].to_f Xmin=t0 if(t0linedraw (MIT-License) LingDongさん作Xmax) Ymin=t0 if(t1 Ymax) end end open(path){|f| d = f.readlines} for i in 0...d.length-1 s0=d[i].index("<polyline points=")+19-1 s1=d[i].index("stroke")-3 s=d[i][s0..s1] d[i]=s.split(",") sleep dt for j in 0...d[i].length/2 t0=d[i][j*2].to_f t1=d[i][j*2+1].to_f a=(MidiMax-MidiMin)/(Xmax-Xmin) MidiX=(t0-Xmin)*a+MidiMin panX=(t0-Xmin)*a/(MidiMax-MidiMin)*1.99-1 MidiY=(t1-Ymin)*a+MidiMin use_synth :saw # Xの音色 p0 = play MidiX,sustain: d[i].length/2*dt, release: 0.1, note_slide: d[i].length/2*dt, pan_slide: d[i].length/2*dt if j==0 control p0, note: MidiX, pan: panX use_synth :square # Yの音色 p1 = play MidiY,sustain: d[i].length/2*dt, release: 0.1, note_slide: d[i].length/2*dt if j==0 control p1, note: MidiY sleep dt end end -----
ORIGIN 以下の 1 attaaaggtt tataccttcc caggtaacaa accaaccaac tttcgatctc ttgtagatct から 29881 aaaaaaaaaa aaaaaaaaaa aaaまでを、コピペ等でテキストファイルに保存して使用しました。coronaGen.txt
# Corona Virus Sound path="coronaGen.txt" d = [] open(path){|f| d = f.readlines} for i in 0...d.length for j in 0...6 for k in 0...10 g=d[i][j*10+j+10+k] play :a, amp:1.5, pan: rrand(-1,1) if g=="a" play :c, amp:1.5, pan: rrand(-1,1) if g=="c" play :g, amp:1.5, pan: rrand(-1,1) if g=="g" play :e, amp:1.5, pan: rrand(-1,1) if g=="t" sleep 0.1 sample :drum_cymbal_closed if g=="a" sample :drum_heavy_kick if g=="c" sample :drum_snare_hard if g=="g" sample :drum_tom_hi_hard if g=="t" sleep 0.1 end end end stop最後まで鳴らすことはまずないと思われますが、最後の行のデータが短いので、エラーで終了すると思います。
// Image2Spectrogram.pde PImage img; void setup() { int w, h; color c; size(200, 200); // 画像ファイルのサイズより大きくする size(横,縦) img=loadImage("Nagi.jpg"); // 画像ファイル名、Processingの画面上にドロップする。 w=img.width; h=img.height; String[] data=new String[1]; data[0]=w+" "+h; image(img, 0, 0); loadPixels(); float maxB=-1,minB=999; for(int i=0;i<h*w;i++) { if(brightness(pixels[i])< minB) minB=brightness(pixels[i]); if(brightness(pixels[i])> maxB) maxB=brightness(pixels[i]); } println("Brightness=",minB," ",maxB); for (int i=0; i<w; i++) { for (int j=0; j<h; j++) { c=get(i, j); float k=(map(brightness(c), minB, maxB, 1, 0)); // SonicPiでのamp値となる. // float k=(map(brightness(c), minB, maxB, 0, 1)); // SonicPiでのamp値となる. 画像を反転させる場合 data[0]=data[0]+" "+nf(k, 0, 2); } data[0]=data[0]+"#"; } saveStrings("Image2Spectrogram.txt", data); // 出力テキストファイル名。Sonic Piでこれを読み込みます。 println("Size= ",w, h); }
use_debug false freqLow=50; # 周波数の下限Hz 0や1は不可。10Hz以上が適当 freqHigh=8000; # 周波数の上限Hz tStep=1.0 # 画像の縦方向の解像度が大きい場合には、同時発音数が多すぎるため、一音の長さ1秒程度まで長くしないと処理速度が追いつかず発音が遅れたりエラーします。 sazae=File.open("/Users/???/Documents/Processing3/Image2Spectrogram/Image2Spectrogram.txt").read.split(" ") # Processingで出力したファイル名をフルパスで指定する w=sazae[0].to_i; h=sazae[1].to_i; freqStep=(freqHigh-freqLow)/h.to_f puts "w,h=",w,h puts "freqStep=",freqStep for i in 0...w for j in 0...h k=i*h+j+2; # attach,sustain,release,ampの値は要検討 play hz_to_midi((h-j-1)*freqStep+freqLow),amp: sazae[k].to_f/20.0,attack:tStep*0.00,sustain:tStep*1,release:tStep*0.0 end sleep tStep puts i,"/",w end
use_debug false freqLow=50; # 周波数の下限Hz 0,1は不可。10Hz以上 freqHigh=8000; # 周波数の上限Hz tStep=1.0 # 画像の縦方向の解像度が大きい場合には、同時発音数が多すぎるため、一音の長さ1秒程度まで長くしないと処理速度が追いつかず発音が遅れたりエラーします。 tRatio=0.1 # 断続音の比率 sazae=File.open("/Users/???/Documents/Processing3/Image2Spectrogram/Image2Spectrogram.txt").read.split(" ") # Processingで出力したファイル名をフルパスで指定する w=sazae[0].to_i; h=sazae[1].to_i; freqStep=(freqHigh-freqLow)/h.to_f puts "w,h=",w,h puts "freqStep=",freqStep for i in 0...w for j in 0...h k=i*h+j+2; # attach,sustain,release,ampの値は要検討 play hz_to_midi((w-j-1)*freqStep+freqLow),amp: sazae[k].to_f/20.0,attack:tStep*0.00*tRatio,sustain:tStep*1*tRatio,release:tStep*0.0*tRatio end sleep tStep puts i,"/",w end初音ミクとさざえさんの元画像
system('say Sonic Pi version 4.4.0. 151scales.') sleep 6 use_synth :piano scale_names.length.times do s1=scale_names.tick puts s1 use_osc "localhost", 4563 osc "/message", (scale :C, s1).to_s s2='say '+s1.to_s system(s2) sleep 1.5 play_pattern_timed(scale :C, s1),0.3 sleep 1 end sleep 1 system('say Thats all.')
# HANON No.1-20 Hanon piano exercises use_synth :piano use_bpm 600 # 600のとき演奏時間8分1秒, 900のとき5分20秒 #for num in 1..20 do (1..20).each do |num| case num when 1 up=(ring 1,3,4,5,6,5,4,3) down=(ring 5,3,2,1,0,1,2,3) when 2 up=(ring 1,3,6,5,4,5,4,3) down=(ring 5,2,0,1,2,1,2,3) when 3 up=(ring 1,3,6,5,4,3,4,5) down=(ring 5,2,0,1,2,3,2,1) when 4 up=(ring 1,2,1,3,6,5,4,3) down=(ring 5,4,5,2,0,1,2,3) when 5 up=(ring 1,6,5,6,4,5,3,4) down=(ring 1,2,1,3,2,4,3,5) when 6 up=(ring 1,6,5,6,4,6,3,6) down=(ring 5,0,1,0,2,0,3,0) when 7 up=(ring 1,3,2,4,3,5,4,2) down=(ring 5,3,4,2,3,1,2,3) when 8 up=(ring 1,3,5,6,4,5,3,4) down=(ring 5,3,1,0,2,1,3,2) when 9 up=(ring 1,3,4,3,5,4,6,5) down=(ring 5,3,2,3,1,2,0,1) when 10 up=(ring 1,6,5,4,3,4,3,4) down=(ring 5,0,1,2,3,2,3,2) when 11 up=(ring 1,3,6,5,6,5,4,5) down=(ring 5,2,0,1,0,1,2,1) when 12 up=(ring 6,1,3,2,1,2,3,1) down=(ring 0,5,3,4,5,4,3,5) when 13 up=(ring 3,1,4,2,5,3,4,5) down=(ring 3,5,2,4,3,1,2,3) when 14 up=(ring 1,2,4,3,4,3,5,4) down=(ring 5,4,2,3,2,3,1,2) when 15 up=(ring 1,3,2,4,3,5,4,6) down=(ring 5,3,4,2,3,1,2,0) when 16 up=(ring 1,3,2,3,6,5,4,5) down=(ring 5,2,3,2,0,1,2,1) when 17 up=(ring 1,3,6,5,7,6,5,6) down=(ring 5,2,0,1,-1,0,1,-1) when 18 up=(ring 1,2,4,3,5,4,2,3) down=(ring 5,4,2,3,1,2,4,3) when 19 up=(ring 1,6,4,5,6,4,3,5) down=(ring 5,0,2,1,0,2,3,1) when 20 up=(ring 3,5,8,10,8,7,8,6) down=(ring 10,8,5,3,5,4,5,3) end num=0 i=0 j=7 num=1 14.times do up.length.times do # stop play scale(:C3,:major,num_octaves: 5)[up[i]-1+j],release:3 play scale(:C2,:major,num_octaves: 5)[up[i]-1+j],release:3 sleep 1 i=i+1 end j=j+1 end i=0 j=7+7+7 ndown=14 ndown=15 if num==1 # 1番の下降回数は例外 ndown.times do down.length.times do # stop play scale(:C3,:major,num_octaves: 5)[down[i]-1+j],release:3 play scale(:C2,:major,num_octaves: 5)[down[i]-1+j],release:3 sleep 1 i=i+1 end j=j-1 end sleep 0.5 play [:C3,:C4],amp:3,sustain:3,release:3 play [:E4,:C5],amp:3,sustain:3,release:3 if num==20 #最後の20番の終わり sleep 8 end
# HANON No.60 use_bpm 60 #60 90 100 use_debug false use_synth :piano panR=0.8 panL=-0.8 a=[] b=[] a0=[] a1=[] b0=[] b1=[] type=[] type[1]=0 a[1]=[[:E4,:G4],:C4] #1 小節番号 measure number b[1]=[[:C3,:E3],:G3] type[2]=0 a[2]=[[:F4,:G4],:D4] b[2]=[[:B2,:D3],:G3] type[3]=0 a[3]=a[1] #2 b[3]=b[1] type[4]=5 a[4]=[[:A4,:C5],:E4] b[4]=[[:A2,:E3],:A3] b1[4]=[[:C3,:E3],:A3] type[5]=0 a[5]=[[:G4,:B4],:D4] #3 b[5]=[[:D3,:G3],:B3] type[6]=0 a[6]=[[:D4,:Fs4,:A4],:C4] b[6]=[:D2,:D3] type[7]=0 a[7]=[[:D4,:G4],:B3]#4 b[7]=[:G2,:G3] type[8]=0 a[8]=a[7] b[8]=[:G2,:F3] type[9]=0 a[9]=a[1]#5 b[9]=b[1] type[10]=0 a[10]=[[:E4,:Gs4],:D4] b[10]=[[:B2,:D3],:E3] type[11]=0 a[11]=[[:E4,:A4],:C4]#6 b[11]=[[:A2,:C3],:E3] type[12]=0 a[12]=[[:A4,:D5],:F4] b[12]=[[:F2,:A2],:D3] type[13]=0 a[13]=[[:G4,:C5],:E4]#7 b[13]=[[:G2,:C3],:E3] type[14]=0 a[14]=[[:G4,:B4],:F4] b[14]=[[:G2,:D3],:G3] type[15]=0 a[15]=a[13]#8 b[15]=b[1] type[16]=0 a[16]=a[13] b[16]=b[1] type[17]=0 a[17]=[[:C5,:E5,:G5],:G4]#9 b[17]=[[:C3,:E3,:G3],:C4] type[18]=0 a[18]=[[:D5,:F5,:G5],:G4] b[18]=[[:B2,:D3,:G3],:B3] type[19]=0 a[19]=a[17]#10 b[19]=b[17] type[20]=0 a[20]=[[:E5,:A5,:C6],:C5] b[20]=[[:A2,:E3],:A3] type[21]=0 a[21]=[[:D5,:G5,:B5],:B4]#11 b[21]=[[:D3,:G3,:B3],:D4] type[22]=0 a[22]=[[:D5,:Fs5,:A5],:C5] b[22]=[[:D3,:Fs3,:A3],:D4] type[23]=0 a[23]=[[:B4,:D5,:G5],:G4]#12 b[23]=[[:G2,:B2,:D3],:G3] type[24]=0 a[24]=a[23] b[24]=[[:G2,:B2,:D3],:F3] type[25]=1 a[25]=a[17]#13 b[25]=[[:C3,:E3,:G3],:C4] b1[25]=[:C3,:E3] type[26]=0 a[26]=[[:D5,:E5,:Gs5],:Gs4] b[26]=[[:B2,:D3,:E3],:B3] type[27]=0 a[27]=[[:C5,:E5,:A5],:A4]#14 b[27]=[[:A2,:C3,:E3],:A3] type[28]=5 a[28]=[[:A5,:D6,:F6],:F5] b[28]=[[:D2,:A3],:D3] b1[28]=[[:F2,:A3],:D3] type[29]=0 a[29]=[[:G5,:C6,:E6],:E5]#15 b[29]=[[:G2,:C3,:E3],:G3] type[30]=0 a[30]=[[:G5,:B5,:D6],:F5] b[30]=[[:G2,:B2,:D3],:G3] type[31]=0 a[31]=[[:E5,:G5,:C6],:C5]#16 b[31]=[[:C3,:E3,:G3],:C4] type[32]=2 a[32]=[:E5,:G5,:C6] b[32]=[:C3,:E3,:G3] type[33]=0 a[33]=[[:C5,:E5],:E4]#17 b[33]=[[:A3],:C4] type[34]=3 a[34]=[[:D5,:F5],:F4] b[34]=[[:Gs3],:B3] a1[34]=[[:C5,:E5],:E4] b1[34]=[[:A3],:C4] type[35]=0 a[35]=[[:A4,:D5],:D4]#18 b[35]=[[:F3],:A3] type[36]=0 a[36]=a[35] b[36]=b[35] type[37]=0 a[37]=[[:A4,:C5],:C4]#19 b[37]=[[:Ds3],:Fs3] type[38]=0 a[38]=[[:B4],:C4] b[38]=b[37] type[39]=0 a[39]=[[:E4,:Gs4],:B3]#20 b[39]=[[:E3],:Gs3] type[40]=0 a[40]=[[:G4],:E4] b[40]=[[:E3,:G3],:B3] type[41]=0 a[41]=[[:C5,:E5],:E4]#21 b[41]=b[33] type[42]=3 a[42]=[[:D5,:F5],:F4] b[42]=b[34] a1[42]=a[41] b1[42]=b[41] type[43]=0 a[43]=[[:A4,:D5],:D4]#22 b[43]=[[:Fs3],:A3] type[44]=0 a[44]=[[:A4,:C5],:Ds4] b[44]=[[:F3],:A3] type[45]=0 a[45]=[[:A4,:A5],:E4]#23 b[45]=[[:E3,:A3],:C4] type[46]=4 a[46]=[[:E4,:Gs4,:C5],:D4] b[46]=[[:E2],:E3] a1[46]=[[:E4,:G4,:B4],:D4] type[47]=0 a[47]=[[:E4,:A4],:C4]#24 b[47]=[[:C3,:E3,:G3],:C4] type[48]=2 a[48]=[:E4,:A4] b[48]=[:C3,:E3,:G3] type[49]=0 a[49]=[[:C5,:E5],:E4]#25 b[49]=[[:A3],:C4] type[50]=3 a[50]=[[:C5,:F5],:F4] b[50]=[[:A3],:C4] a1[50]=[[:C5,:Fs5],:Fs4] b1[50]=[[:Af3],:C4] type[51]=0 a[51]=[[:C5,:G5],:G4]#26 b[51]=[[:G3,:C4],:E4] type[52]=0 a[52]=[[:C5,:A5],:A4] b[52]=[[:Fs3,:C4],:Ds4] type[53]=0 a[53]=[[:C5,:E5],:G4]#27 b[53]=[[:G3,:C4],:E4] type[54]=0 a[54]=[[:G4,:B4,:E5],:F4] b[54]=[[:G2],:G3] type[55]=0 a[55]=[[:E4,:G4,:C5],:C4]#28 b[55]=[[:C2],:C3] type[56]=2 a[56]=[:E4,:G4,:C5] b[56]=[:C2] type[57]=0 a[57]=[[:A5,:C6],:C5]#29 b[57]=[[:F3,:A3],:C4] a1[57]=[[:A5,:Ds6],:Ds5] type[58]=4 a[58]=[[:A5,:D6],:D5] b[58]=[[:F3,:A3],:C4] a1[58]=[[:A5,:Ds6],:Ds5] type[59]=0 a[59]=[[:A5,:E6],:E5]#30 b[59]=[[:E3,:A3],:C4] type[60]=0 a[60]=[[:A5,:F6],:F5] b[60]=[[:Ds3,:A3],:C4] type[61]=0 a[61]=[[:A5,:C6,:E6],:E5]#31 b[61]=[[:E3,:A3],:C4] type[62]=4 a[62]=[[:E5,:Gs6,:C6],:D5] b[62]=[[:E2],:E3] a1[62]=[[:E5,:Gs6,:B5],:D5] type[63]=0 a[63]=[[:C5,:E5,:A5],:A4]#32 b[63]=[[:A2],:A3] type[64]=2 a[64]=[:C5,:E5,:A5] b[64]=[:A2] type[65]=0 a[65]=[[:C5,:E5],:A4]#33 b[65]=[[:A3,:C4],:E4] type[66]=4 a[66]=[[:C5,:F5],:A4] b[66]=b[65] a1[66]=a[65] type[67]=4 a[67]=[[:E5,:B5],:C5]#34 b[67]=[[:A3,:C4],:E4] a1[67]=[[:E5,:G5],:C5] type[68]=3 a[68]=[[:A4,:F5],:F4] b[68]=[[:D3,:A3],:D4] a1[68]=[[:A4,:D5],:F4] b1[68]=[[:F3,:A3],:D4] type[69]=0 a[69]=[[:A4,:C5],:E4]#35 b[69]=[[:E3,:A3],:C4] type[70]=0 a[70]=[[:Gs4,:B4],:E4] b[70]=[[:E3,:Gs3],:B3] type[71]=0 a[71]=[[:A4,:D5],:F4]#36 b[71]=[[:F3],:A3] type[72]=0 a[72]=[[:A4,:C5],:E4] b[72]=[[:A3],:C4] type[73]=0 a[73]=[[:C5,:E5],:A4]#37 b[73]=[[:A2,:C3],:E3] type[74]=4 a[74]=[[:C5,:F5],:A4] b[74]=[[:A2,:C3],:E3] a1[74]=[[:C5,:E5],:A4] type[75]=4 a[75]=[[:E5,:C6],:C5]#38 b[75]=[[:A2,:C3],:E3] a1[75]=[[:E5,:A5],:C5] type[76]=3 a[76]=[[:A4,:F5],:F4] b[76]=[[:D2,:A2],:D3] a1[76]=[[:A4,:D5],:F4] b1[76]=[[:F2,:A2],:D3] type[77]=0 a[77]=[[:A4,:C5],:E4]#39 b[77]=[[:E2,:A2],:C3] type[78]=4 a[78]=[[:E4,:Gs4,:C5],:D4] b[78]=[[:E2,:Gs4,:B2],:C3] a1[78]=[[:E4,:Gs4,:B4],:D4] type[79]=0 a[79]=[[:C4,:E4,:A4],:A3]#40 b[79]=[[:A2,:C3],:E3] type[80]=5 a[80]=[[:C4,:E4,:A4],:A3] b[80]=[[:E2],:E3] b1[80]=[[:C2],:C3] type[81]=0 a[81]=[[:C4,:E4,:A4],:A3]#41 b[81]=[[:A2,:C3],:E3] type[82]=5 a[82]=[[:C4,:E4,:A4],:A3] b[82]=[[:E2],:E3] b1[82]=[[:C2],:C3] type[83]=0 a[83]=[[:C4,:E4,:A4],:A3]#42 b[83]=[[:A2,:C3],:E3] type[84]=2 a[84]=[:C4,:E4,:A4] b[84]=[[:E2],:E3] a1[84]=[:C4,:E4,:A4] b1[84]=[:C2] type[85]=0 a[85]=[[:E4,:G5],:C4]#43==#1 b[85]=[[:C3,:E3],:G3] type[86]=0 a[86]=[[:F4,:G4],:D4] b[86]=[[:B2,:D3],:G3] for ii in 85..112 # ここで変数iを使うとiがグローバル変数になってしまい、in_thred内のiに干渉してしまいます. type[ii]=type[ii-84]#43==1 , #56==14 a[ii]=a[ii-84] b[ii]=b[ii-84] a1[ii]=a1[ii-84] b1[ii]=b1[ii-84] end type[113]=0 a[113]=[[:G5,:C6,:E6],:E5]#57 b[113]=[[:G2,:C3,:E3],:G3] type[114]=0 a[114]=[[:G5,:B5,:D6],:F5] b[114]=[[:G2,:B2,:D3],:G3] type[115]=0 a[115]=[[:E5,:G5,:C6],:C5]#58 b[115]=[[:C3,:E3,:G3],:C4] type[116]=5 a[116]=a[115] b[116]=[[:E3,:G3,:C4],:E4] b1[116]=b[115] type[117]=0 a[117]=[[:G5,:C6,:E6],:E5]#59 b[117]=[[:G2,:C3,:E3],:G3] type[118]=5 a[118]=a[117] b[118]=[[:C3,:E3,:G3],:C4] b1[118]=b[117] type[119]=0 a[119]=[[:C5,:E6,:G6],:G4]#60 b[119]=[[:E2,:G2,:C3],:E3] type[120]=5 a[120]=a[119] b[120]=[[:G2,:C3,:E3],:G3] b1[120]=b[119] type[121]=0 a[121]=[[:E5,:G5,:C6],:C5]#61 b[121]=[[:C2,:E2,:G2],:C3] type[122]=0 a[122]=a[121] b[122]=b[121] type[123]=6 a[123]=[:E5,:G5,:C6]#62 b[123]=[:C2,:E2,:G2] n1=1 #1 n2=123 #123 # 左手 in_thread do #stop #コメントを解除すると左手だけとなる with_fx :reverb do for i in n1..n2 do puts "######## #{i} ############ #{i}" if type[i]==2 # 左右2小節目の最後の四分音符のタイのとき play a[i],release:2,amp:0.8,decay:1,pan: panR sleep 2.5 ## elsif type[i]==3 ||type[i]==4 # 3拍目と4拍目が異なるとき 4.times do play_pattern_timed a[i],0.125,amp:0.8,pan: panR end 4.times do play_pattern_timed a1[i],0.125,amp:0.8,pan: panR end elsif type[i]==6 play a[i],decay:2,release:3,amp:0.8,pan: panR,amp:2 sleep 4 else # type==0のとき 8.times do play_pattern_timed a[i],0.125,amp:0.8,pan: panR end end # else # end end end end # 右手 in_thread do #stop #コメントを解除すると右手だけとなる with_fx :reverb do for i in n1..n2 do if type[i]==1 then # 左の先頭が特殊 play_pattern_timed b1[i],0.125,amp:0.6,pan: panL 7.times do play_pattern_timed b[i],0.125,amp:0.6,pan: panL end elsif type[i]==2 # 左右2小節目の最後の四分音符がタイのとき play b[i],release:2,amp:1,decay:1,pan: panL sleep 2.5 ## elsif type[i]==3 ||type[i]==5 # 3拍目と4拍目が異なるとき 4.times do play_pattern_timed b[i],0.125,amp:0.6,pan: panL end 4.times do play_pattern_timed b1[i],0.125,amp:0.6,pan: panL end elsif type[i]==6 play b[i],decay:2,release:3,amp:0.6,pan: panL, amp:2 sleep 4 else # type==0のとき 8.times do play_pattern_timed b[i],0.125,amp:0.6,pan: panL end end end end end