challenge Tiny MML

文字列の入力をとり、音を鳴らすプログラムを作ってください。

入力はcがド、dがレ、eがミ、fがファ、gがソ、aがラ、bがシ、rが休符とします。この8文字以外の文字は入力に含まれていないと仮定して構いません。おのおのの音符・休符は八分音符・八分休符とします。

オクターブや音の長さの変更、同時発音などの機能は不要です。

サンプル入力(カエルの歌)

cdefedcrefgagfercrcrcrcrcdefedcr

Posted feedbacks - Smalltalk

Squeak Smalltalk で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
| score pitches duration loudness sequence sound |
score := 'cdefedcrefgagfercrcrcrcrcdefedcr'.
duration := 1/8 * 2.
loudness := 500.
pitches := FMSound chromaticPitchesFrom: #c4.
sequence := score asArray collect: [:pName |
   pName = $r
      ifTrue: [{#rest. duration}]
      ifFalse: [{pitches at: ('c d ef g a b' indexOf: pName). duration. loudness}]].
sound := AbstractSound noteSequenceOn: FMSound default from: sequence.
sound play

Index

Feed

Other

Link

Pathtraq

loading...