はるかかなた昔の、MZ-80Bが採用していた単音3オクターブの範囲の音楽再生を行うPLAY文、それに準拠したポケットコンピュータ用の音楽再生プログラムのデータ「アルハンブラの想い出」の再生を行うため「だけ」に、そのMML再生プログラムをAppleScriptで作ってみたものです(2時間ぐらいだったか)。
音階再生用に、オープンソースの「MPSoundEngine」フレームワークをUniversal Binaryでビルドし直して、これを用いて音階データと音の長さのデータのテーブルを作って再生しています。
–> Download mpSoundKit_univ.framework(To ~/Library/Frameworks)
オリジナルのMZにしてもポケットコンピュータのMML再生プログラムにしても、単音しか出ない仕様ですが、このデータの原作者が楽譜を細切れにしてアルペジオ奏法で演奏させているかのような効果を生み出しています。これは、当時も腰を抜かしましたが、普通こんなものはやらない狂気の産物、人類レベルの遺産といえます。
MPSoundEngineをフレームワーク化したものを呼び出しているため、実行にはScript Debuggerが必要です。macOS 11よりも古い環境では以前に掲載したFramework(Intelバイナリのみ)がそのまま利用できるはずです。
まだ、いまひとつ休符(R)の処理などがうまく行っていないようで、この曲以外のデータを再生させると、首をひねってしまう演奏をしてしまうものの、それはオリジナルのデータの出来がよくなかったのか、あるいはこのプログラムの再現度が高くないためかは不明です。
AppleScript名:SHARP MZ MML再生_アルハンブラ_mono.scptd |
— – Created by: Takaaki Naganoya – Created on: 2022/12/22 — – Copyright © 2022 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use framework "mpSoundKit" –https://github.com/matthiasplappert/MPSoundEngine use scripting additions script spd property musStr : "" property musList : {} property mmlList : {} end script set octL to {"-C", "-#C", "-D", "-#D", "-E", "-F", "-#F", "-G", "-#G", "-A", "-#A", "-B", "C", "#C", "D", "#D", "E", "F", "#F", "G", "#G", "A", "#A", "B", "+C", "+#C", "+D", "+#D", "+E", "+F", "+#F", "+G", "+#G", "+A", "+#A", "+B"} set lenL to {130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.0, 196.0, 207.65, 220.0, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.0, 415.3, 440.0, 466.16, 493.88, 523.25, 554.37, 587.33, 622.25, 659.25, 698.46, 739.99, 783.99, 830.61, 880.0, 932.33, 987.77} set noteList to {"9", "8", "7", "6", "5", "4", "3", "2", "1", "0"} set noteTime to {4, 3, 2, 1.5, 1, 0.75, 0.5, 0.375, 0.25, 0.125} set aDict to current application’s NSMutableDictionary’s dictionaryWithObjects:(lenL) forKeys:(octL) set bDict to current application’s NSMutableDictionary’s dictionaryWithObjects:(noteTime) forKeys:(noteList) set (musStr of spd) to "-A0+E+E+EE+E+E+E+C0+E+E+EE+E+E+EB0+D+D+DE+D+D+D-A0+C+C+CE+C+C+CA0+C+C+CE+C+C+CB0+D+D+DE+D+D+D-A0+E+E+EE+E+E+E+C0+E+E+EE+E+E+E+C0+E+E+EE+E+E+E-A0+E+E+EE+E+E+E+C0+E+E+EE+E+E+E+D0+F+F+FG+F+F+FC0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G+E0+F+F+FG+F+F+FC0+E+E+EG+E+E+E+C0+E+E+EG+E+E+E+D0+F+F+FG+F+F+FC0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G+E0+G+G+GG+G+G+GC0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G+E0+G+G+GG+G+G+G-F0+C+C+CC+C+C+CA0+C+C+CC+C+C+CG0+B+B+BC+B+B+B-F0+A+A+AC+A+A+A+F0+A+A+AC+A+A+A-D0+B+B+BF+B+B+B-E0+A+A+AB+A+A+A+E0+#G+#G+#GB0+#G+#G+#G+E0+#G+#G+#GB0+#G+#G+#G-E0+#G+#G+#G+D0+#G+#G+#G+E0+#G+#G+#G+D0+#G+#G+#G+E0+#G+#G+#G+D0+#G+#G+#G-A0+#A+#A+#A+#C0+#A+#A+#A+E0+#A+#A+#A+#C0+#A+#A+#A+E0+A+A+A+#C0+A+A+A#C0+G+G+GA+G+G+G+E0+G+G+GA+G+G+G+F0+A+A+AA+A+A+AD0+G+G+G+E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+E+E+EE+E+E+E-A0+E+E+EE+E+E+E+#C0+E+E+EE+E+E+E+#C0+E+E+EE+E+E+E-E0+#G+#G+#GE0+#G+#G+#G+E0+#G+#G+#GE0+#G+#G+#G+E0+#G+#G+#GE0+#G+#G+#G-E0+#F+#F+#FE0+#F+#F+#F+#C0+E+E+EE+E+E+EB0+D+D+DE+D+D+D-A0+#C+#C+#CE0+#C+#C+#CA0+#C+#C+#CE0+#C+#C+#C#F0+#C+#C+#CA0+#C+#C+#C-A0+#C+#C+#CE0+#C+#C+#CA0+#C+#C+#C-E0+#C+#C+#C-#B0+#C+#C+#C#C0+#C+#C+#C-A0+#C+#C+#CE0+#C+#C+#CA0+#C+#C+#C-E0+#C+#C+#C-#B0+#C+#C+#C#C0+#C+#C+#C-A3EA+#C+E+A+E8A7R7" set baseTime to 0.25 set (musList of spd) to characters of (musStr of spd) set octV to 0 –Ave Octave set defaultNote to {octave:0, noteStr:missing value, sharpF:missing value, flatF:missing value, noteLength:missing value} copy defaultNote to curNote set prevNoteLength to -1 set (mmlList of spd) to {} repeat with i in (musList of spd) set j to contents of i considering case if j = "-" then if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote set prevNoteLength to noteLength of curNote copy defaultNote to curNote set (noteLength of curNote) to prevNoteLength set octave of curNote to -1 else set octave of curNote to -1 end if else if j = "+" then if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote set prevNoteLength to noteLength of curNote copy defaultNote to curNote set (noteLength of curNote) to prevNoteLength set octave of curNote to 1 else set octave of curNote to 1 end if (* else if j = "b" then –Flat if noteStr of curNote is not equal to missing value then set the end of mmlList to curNote set prevNoteLength to noteLength of curNote copy defaultNote to curNote set (noteLength of curNote) to prevNoteLength else set flatF of curNote to true end if *) else if j = "#" then –Sharp if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote set prevNoteLength to noteLength of curNote copy defaultNote to curNote set (noteLength of curNote) to prevNoteLength else set sharpF of curNote to true end if else if j is in {"C", "D", "E", "F", "G", "A", "B", "R"} then if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote set prevNoteLength to noteLength of curNote copy defaultNote to curNote set (noteLength of curNote) to prevNoteLength end if set (noteStr of curNote) to j else if j is in noteList then set noteLength of curNote to j if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote set prevNoteLength to noteLength of curNote copy defaultNote to curNote set (noteLength of curNote) to prevNoteLength else set the end of (mmlList of spd) to curNote end if end if end considering end repeat if noteStr of curNote is not equal to missing value then set the end of (mmlList of spd) to curNote –Append Last Item –return mmlList –Play set engine to current application’s MPMonoSoundEngine’s alloc()’s init() engine’s start() repeat with i in (mmlList of spd) set j to contents of i set curOctave to octave of j set curOctaveStr to encodeOctave(curOctave) of me set sharpFlag to sharpF of j set flatFlag to flatF of j set sfStr to encodeSharpAndFlat(sharpFlag, flatFlag) of me set noteLenStr to noteLength of j set noteLenTime to (bDict’s valueForKey:noteLenStr) as real set noteString to noteStr of j if noteString = "R" then engine’s |stop|() (current application’s NSThread’s sleepForTimeInterval:(((noteLenTime * baseTime)) as real)) –delay (noteLenTime * baseTime) / 2 engine’s start() else set noteKey to curOctaveStr & sfStr & noteString try set noteFreq to (aDict’s valueForKey:noteKey) as real on error engine’s |stop|() return end try (engine’s channel’s setFrequency:noteFreq) –(engine’s rightChannel()’s setFrequency:noteFreq) (current application’s NSThread’s sleepForTimeInterval:(((noteLenTime * baseTime)) as real)) end if end repeat engine’s |stop|() on encodeSharpAndFlat(sharpF, flatF) if {sharpF, flatF} = {missing value, missing value} then return "" if {sharpF, flatF} = {true, missing value} then return "#" if {sharpF, flatF} = {missing value, true} then return "b" if {sharpF, flatF} = {true, true} then error "Sharp and Flat in one note" end encodeSharpAndFlat on encodeOctave(curOctave) if curOctave = 0 then set curOctaveStr to "" else if curOctave = 1 then set curOctaveStr to "+" else if curOctave = -1 then set curOctaveStr to "-" end if return curOctaveStr end encodeOctave |
More from my site
(Visited 43 times, 1 visits today)