Moved backend and UI functionality into the datum/song class and made in generalizable for special-case functionalities for player checks, etc

This commit is contained in:
Tastyfish
2013-03-20 04:52:17 -04:00
parent 02b3b35b72
commit 806d784b16
2 changed files with 378 additions and 716 deletions
+371 -319
View File
@@ -5,223 +5,221 @@
var/list/lines = new()
var/tempo = 5
/obj/structure/device/piano
name = "space minimoog"
icon = 'icons/obj/musician.dmi'
icon_state = "minimoog"
anchored = 1
density = 1
var/datum/song/song
var/playing = 0
var/help = 0
var/edit = 1
var/repeat = 0
var/playing = 0 // if we're playing
var/help = 0 // if help is open
var/edit = 1 // if we're in editing mode
var/repeat = 0 // number of times remaining to repeat
var/max_repeats = 10 // maximum times we can repeat
/obj/structure/device/piano/New()
if(prob(50))
name = "space minimoog"
desc = "This is a minimoog, like a space piano, but more spacey!"
icon_state = "minimoog"
else
name = "space piano"
desc = "This is a space piano, like a regular piano, but always in tune! Even if the musician isn't."
icon_state = "piano"
var/instrumentDir = "piano" // the folder with the sounds
var/instrumentExt = "ogg" // the file extension
var/obj/instrumentObj = null // the associated obj playing the sound
/obj/structure/device/piano/proc/playnote(var/note as text)
/datum/song/New(dir, obj)
instrumentDir = dir
instrumentObj = obj
/datum/song/proc/playnote(var/note as text)
//world << "Note: [note]"
var/soundfile
/*BYOND loads resource files at compile time if they are ''. This means you can't really manipulate them dynamically.
Tried doing it dynamically at first but its more trouble than its worth. Would have saved many lines tho.*/
switch(note)
if("Cn1") soundfile = 'sound/piano/Cn1.ogg'
if("C#1") soundfile = 'sound/piano/C#1.ogg'
if("Db1") soundfile = 'sound/piano/Db1.ogg'
if("Dn1") soundfile = 'sound/piano/Dn1.ogg'
if("D#1") soundfile = 'sound/piano/D#1.ogg'
if("Eb1") soundfile = 'sound/piano/Eb1.ogg'
if("En1") soundfile = 'sound/piano/En1.ogg'
if("E#1") soundfile = 'sound/piano/E#1.ogg'
if("Fb1") soundfile = 'sound/piano/Fb1.ogg'
if("Fn1") soundfile = 'sound/piano/Fn1.ogg'
if("F#1") soundfile = 'sound/piano/F#1.ogg'
if("Gb1") soundfile = 'sound/piano/Gb1.ogg'
if("Gn1") soundfile = 'sound/piano/Gn1.ogg'
if("G#1") soundfile = 'sound/piano/G#1.ogg'
if("Ab1") soundfile = 'sound/piano/Ab1.ogg'
if("An1") soundfile = 'sound/piano/An1.ogg'
if("A#1") soundfile = 'sound/piano/A#1.ogg'
if("Bb1") soundfile = 'sound/piano/Bb1.ogg'
if("Bn1") soundfile = 'sound/piano/Bn1.ogg'
if("B#1") soundfile = 'sound/piano/B#1.ogg'
if("Cb2") soundfile = 'sound/piano/Cb2.ogg'
if("Cn2") soundfile = 'sound/piano/Cn2.ogg'
if("C#2") soundfile = 'sound/piano/C#2.ogg'
if("Db2") soundfile = 'sound/piano/Db2.ogg'
if("Dn2") soundfile = 'sound/piano/Dn2.ogg'
if("D#2") soundfile = 'sound/piano/D#2.ogg'
if("Eb2") soundfile = 'sound/piano/Eb2.ogg'
if("En2") soundfile = 'sound/piano/En2.ogg'
if("E#2") soundfile = 'sound/piano/E#2.ogg'
if("Fb2") soundfile = 'sound/piano/Fb2.ogg'
if("Fn2") soundfile = 'sound/piano/Fn2.ogg'
if("F#2") soundfile = 'sound/piano/F#2.ogg'
if("Gb2") soundfile = 'sound/piano/Gb2.ogg'
if("Gn2") soundfile = 'sound/piano/Gn2.ogg'
if("G#2") soundfile = 'sound/piano/G#2.ogg'
if("Ab2") soundfile = 'sound/piano/Ab2.ogg'
if("An2") soundfile = 'sound/piano/An2.ogg'
if("A#2") soundfile = 'sound/piano/A#2.ogg'
if("Bb2") soundfile = 'sound/piano/Bb2.ogg'
if("Bn2") soundfile = 'sound/piano/Bn2.ogg'
if("B#2") soundfile = 'sound/piano/B#2.ogg'
if("Cb3") soundfile = 'sound/piano/Cb3.ogg'
if("Cn3") soundfile = 'sound/piano/Cn3.ogg'
if("C#3") soundfile = 'sound/piano/C#3.ogg'
if("Db3") soundfile = 'sound/piano/Db3.ogg'
if("Dn3") soundfile = 'sound/piano/Dn3.ogg'
if("D#3") soundfile = 'sound/piano/D#3.ogg'
if("Eb3") soundfile = 'sound/piano/Eb3.ogg'
if("En3") soundfile = 'sound/piano/En3.ogg'
if("E#3") soundfile = 'sound/piano/E#3.ogg'
if("Fb3") soundfile = 'sound/piano/Fb3.ogg'
if("Fn3") soundfile = 'sound/piano/Fn3.ogg'
if("F#3") soundfile = 'sound/piano/F#3.ogg'
if("Gb3") soundfile = 'sound/piano/Gb3.ogg'
if("Gn3") soundfile = 'sound/piano/Gn3.ogg'
if("G#3") soundfile = 'sound/piano/G#3.ogg'
if("Ab3") soundfile = 'sound/piano/Ab3.ogg'
if("An3") soundfile = 'sound/piano/An3.ogg'
if("A#3") soundfile = 'sound/piano/A#3.ogg'
if("Bb3") soundfile = 'sound/piano/Bb3.ogg'
if("Bn3") soundfile = 'sound/piano/Bn3.ogg'
if("B#3") soundfile = 'sound/piano/B#3.ogg'
if("Cb4") soundfile = 'sound/piano/Cb4.ogg'
if("Cn4") soundfile = 'sound/piano/Cn4.ogg'
if("C#4") soundfile = 'sound/piano/C#4.ogg'
if("Db4") soundfile = 'sound/piano/Db4.ogg'
if("Dn4") soundfile = 'sound/piano/Dn4.ogg'
if("D#4") soundfile = 'sound/piano/D#4.ogg'
if("Eb4") soundfile = 'sound/piano/Eb4.ogg'
if("En4") soundfile = 'sound/piano/En4.ogg'
if("E#4") soundfile = 'sound/piano/E#4.ogg'
if("Fb4") soundfile = 'sound/piano/Fb4.ogg'
if("Fn4") soundfile = 'sound/piano/Fn4.ogg'
if("F#4") soundfile = 'sound/piano/F#4.ogg'
if("Gb4") soundfile = 'sound/piano/Gb4.ogg'
if("Gn4") soundfile = 'sound/piano/Gn4.ogg'
if("G#4") soundfile = 'sound/piano/G#4.ogg'
if("Ab4") soundfile = 'sound/piano/Ab4.ogg'
if("An4") soundfile = 'sound/piano/An4.ogg'
if("A#4") soundfile = 'sound/piano/A#4.ogg'
if("Bb4") soundfile = 'sound/piano/Bb4.ogg'
if("Bn4") soundfile = 'sound/piano/Bn4.ogg'
if("B#4") soundfile = 'sound/piano/B#4.ogg'
if("Cb5") soundfile = 'sound/piano/Cb5.ogg'
if("Cn5") soundfile = 'sound/piano/Cn5.ogg'
if("C#5") soundfile = 'sound/piano/C#5.ogg'
if("Db5") soundfile = 'sound/piano/Db5.ogg'
if("Dn5") soundfile = 'sound/piano/Dn5.ogg'
if("D#5") soundfile = 'sound/piano/D#5.ogg'
if("Eb5") soundfile = 'sound/piano/Eb5.ogg'
if("En5") soundfile = 'sound/piano/En5.ogg'
if("E#5") soundfile = 'sound/piano/E#5.ogg'
if("Fb5") soundfile = 'sound/piano/Fb5.ogg'
if("Fn5") soundfile = 'sound/piano/Fn5.ogg'
if("F#5") soundfile = 'sound/piano/F#5.ogg'
if("Gb5") soundfile = 'sound/piano/Gb5.ogg'
if("Gn5") soundfile = 'sound/piano/Gn5.ogg'
if("G#5") soundfile = 'sound/piano/G#5.ogg'
if("Ab5") soundfile = 'sound/piano/Ab5.ogg'
if("An5") soundfile = 'sound/piano/An5.ogg'
if("A#5") soundfile = 'sound/piano/A#5.ogg'
if("Bb5") soundfile = 'sound/piano/Bb5.ogg'
if("Bn5") soundfile = 'sound/piano/Bn5.ogg'
if("B#5") soundfile = 'sound/piano/B#5.ogg'
if("Cb6") soundfile = 'sound/piano/Cb6.ogg'
if("Cn6") soundfile = 'sound/piano/Cn6.ogg'
if("C#6") soundfile = 'sound/piano/C#6.ogg'
if("Db6") soundfile = 'sound/piano/Db6.ogg'
if("Dn6") soundfile = 'sound/piano/Dn6.ogg'
if("D#6") soundfile = 'sound/piano/D#6.ogg'
if("Eb6") soundfile = 'sound/piano/Eb6.ogg'
if("En6") soundfile = 'sound/piano/En6.ogg'
if("E#6") soundfile = 'sound/piano/E#6.ogg'
if("Fb6") soundfile = 'sound/piano/Fb6.ogg'
if("Fn6") soundfile = 'sound/piano/Fn6.ogg'
if("F#6") soundfile = 'sound/piano/F#6.ogg'
if("Gb6") soundfile = 'sound/piano/Gb6.ogg'
if("Gn6") soundfile = 'sound/piano/Gn6.ogg'
if("G#6") soundfile = 'sound/piano/G#6.ogg'
if("Ab6") soundfile = 'sound/piano/Ab6.ogg'
if("An6") soundfile = 'sound/piano/An6.ogg'
if("A#6") soundfile = 'sound/piano/A#6.ogg'
if("Bb6") soundfile = 'sound/piano/Bb6.ogg'
if("Bn6") soundfile = 'sound/piano/Bn6.ogg'
if("B#6") soundfile = 'sound/piano/B#6.ogg'
if("Cb7") soundfile = 'sound/piano/Cb7.ogg'
if("Cn7") soundfile = 'sound/piano/Cn7.ogg'
if("C#7") soundfile = 'sound/piano/C#7.ogg'
if("Db7") soundfile = 'sound/piano/Db7.ogg'
if("Dn7") soundfile = 'sound/piano/Dn7.ogg'
if("D#7") soundfile = 'sound/piano/D#7.ogg'
if("Eb7") soundfile = 'sound/piano/Eb7.ogg'
if("En7") soundfile = 'sound/piano/En7.ogg'
if("E#7") soundfile = 'sound/piano/E#7.ogg'
if("Fb7") soundfile = 'sound/piano/Fb7.ogg'
if("Fn7") soundfile = 'sound/piano/Fn7.ogg'
if("F#7") soundfile = 'sound/piano/F#7.ogg'
if("Gb7") soundfile = 'sound/piano/Gb7.ogg'
if("Gn7") soundfile = 'sound/piano/Gn7.ogg'
if("G#7") soundfile = 'sound/piano/G#7.ogg'
if("Ab7") soundfile = 'sound/piano/Ab7.ogg'
if("An7") soundfile = 'sound/piano/An7.ogg'
if("A#7") soundfile = 'sound/piano/A#7.ogg'
if("Bb7") soundfile = 'sound/piano/Bb7.ogg'
if("Bn7") soundfile = 'sound/piano/Bn7.ogg'
if("B#7") soundfile = 'sound/piano/B#7.ogg'
if("Cb8") soundfile = 'sound/piano/Cb8.ogg'
if("Cn8") soundfile = 'sound/piano/Cn8.ogg'
if("C#8") soundfile = 'sound/piano/C#8.ogg'
if("Db8") soundfile = 'sound/piano/Db8.ogg'
if("Dn8") soundfile = 'sound/piano/Dn8.ogg'
if("D#8") soundfile = 'sound/piano/D#8.ogg'
if("Eb8") soundfile = 'sound/piano/Eb8.ogg'
if("En8") soundfile = 'sound/piano/En8.ogg'
if("E#8") soundfile = 'sound/piano/E#8.ogg'
if("Fb8") soundfile = 'sound/piano/Fb8.ogg'
if("Fn8") soundfile = 'sound/piano/Fn8.ogg'
if("F#8") soundfile = 'sound/piano/F#8.ogg'
if("Gb8") soundfile = 'sound/piano/Gb8.ogg'
if("Gn8") soundfile = 'sound/piano/Gn8.ogg'
if("G#8") soundfile = 'sound/piano/G#8.ogg'
if("Ab8") soundfile = 'sound/piano/Ab8.ogg'
if("An8") soundfile = 'sound/piano/An8.ogg'
if("A#8") soundfile = 'sound/piano/A#8.ogg'
if("Bb8") soundfile = 'sound/piano/Bb8.ogg'
if("Bn8") soundfile = 'sound/piano/Bn8.ogg'
if("B#8") soundfile = 'sound/piano/B#8.ogg'
if("Cb9") soundfile = 'sound/piano/Cb9.ogg'
if("Cn9") soundfile = 'sound/piano/Cn9.ogg'
if("Cn1") soundfile = "sound/[instrumentDir]/Cn1.[instrumentExt]"
if("C#1") soundfile = "sound/[instrumentDir]/C#1.[instrumentExt]"
if("Db1") soundfile = "sound/[instrumentDir]/Db1.[instrumentExt]"
if("Dn1") soundfile = "sound/[instrumentDir]/Dn1.[instrumentExt]"
if("D#1") soundfile = "sound/[instrumentDir]/D#1.[instrumentExt]"
if("Eb1") soundfile = "sound/[instrumentDir]/Eb1.[instrumentExt]"
if("En1") soundfile = "sound/[instrumentDir]/En1.[instrumentExt]"
if("E#1") soundfile = "sound/[instrumentDir]/E#1.[instrumentExt]"
if("Fb1") soundfile = "sound/[instrumentDir]/Fb1.[instrumentExt]"
if("Fn1") soundfile = "sound/[instrumentDir]/Fn1.[instrumentExt]"
if("F#1") soundfile = "sound/[instrumentDir]/F#1.[instrumentExt]"
if("Gb1") soundfile = "sound/[instrumentDir]/Gb1.[instrumentExt]"
if("Gn1") soundfile = "sound/[instrumentDir]/Gn1.[instrumentExt]"
if("G#1") soundfile = "sound/[instrumentDir]/G#1.[instrumentExt]"
if("Ab1") soundfile = "sound/[instrumentDir]/Ab1.[instrumentExt]"
if("An1") soundfile = "sound/[instrumentDir]/An1.[instrumentExt]"
if("A#1") soundfile = "sound/[instrumentDir]/A#1.[instrumentExt]"
if("Bb1") soundfile = "sound/[instrumentDir]/Bb1.[instrumentExt]"
if("Bn1") soundfile = "sound/[instrumentDir]/Bn1.[instrumentExt]"
if("B#1") soundfile = "sound/[instrumentDir]/B#1.[instrumentExt]"
if("Cb2") soundfile = "sound/[instrumentDir]/Cb2.[instrumentExt]"
if("Cn2") soundfile = "sound/[instrumentDir]/Cn2.[instrumentExt]"
if("C#2") soundfile = "sound/[instrumentDir]/C#2.[instrumentExt]"
if("Db2") soundfile = "sound/[instrumentDir]/Db2.[instrumentExt]"
if("Dn2") soundfile = "sound/[instrumentDir]/Dn2.[instrumentExt]"
if("D#2") soundfile = "sound/[instrumentDir]/D#2.[instrumentExt]"
if("Eb2") soundfile = "sound/[instrumentDir]/Eb2.[instrumentExt]"
if("En2") soundfile = "sound/[instrumentDir]/En2.[instrumentExt]"
if("E#2") soundfile = "sound/[instrumentDir]/E#2.[instrumentExt]"
if("Fb2") soundfile = "sound/[instrumentDir]/Fb2.[instrumentExt]"
if("Fn2") soundfile = "sound/[instrumentDir]/Fn2.[instrumentExt]"
if("F#2") soundfile = "sound/[instrumentDir]/F#2.[instrumentExt]"
if("Gb2") soundfile = "sound/[instrumentDir]/Gb2.[instrumentExt]"
if("Gn2") soundfile = "sound/[instrumentDir]/Gn2.[instrumentExt]"
if("G#2") soundfile = "sound/[instrumentDir]/G#2.[instrumentExt]"
if("Ab2") soundfile = "sound/[instrumentDir]/Ab2.[instrumentExt]"
if("An2") soundfile = "sound/[instrumentDir]/An2.[instrumentExt]"
if("A#2") soundfile = "sound/[instrumentDir]/A#2.[instrumentExt]"
if("Bb2") soundfile = "sound/[instrumentDir]/Bb2.[instrumentExt]"
if("Bn2") soundfile = "sound/[instrumentDir]/Bn2.[instrumentExt]"
if("B#2") soundfile = "sound/[instrumentDir]/B#2.[instrumentExt]"
if("Cb3") soundfile = "sound/[instrumentDir]/Cb3.[instrumentExt]"
if("Cn3") soundfile = "sound/[instrumentDir]/Cn3.[instrumentExt]"
if("C#3") soundfile = "sound/[instrumentDir]/C#3.[instrumentExt]"
if("Db3") soundfile = "sound/[instrumentDir]/Db3.[instrumentExt]"
if("Dn3") soundfile = "sound/[instrumentDir]/Dn3.[instrumentExt]"
if("D#3") soundfile = "sound/[instrumentDir]/D#3.[instrumentExt]"
if("Eb3") soundfile = "sound/[instrumentDir]/Eb3.[instrumentExt]"
if("En3") soundfile = "sound/[instrumentDir]/En3.[instrumentExt]"
if("E#3") soundfile = "sound/[instrumentDir]/E#3.[instrumentExt]"
if("Fb3") soundfile = "sound/[instrumentDir]/Fb3.[instrumentExt]"
if("Fn3") soundfile = "sound/[instrumentDir]/Fn3.[instrumentExt]"
if("F#3") soundfile = "sound/[instrumentDir]/F#3.[instrumentExt]"
if("Gb3") soundfile = "sound/[instrumentDir]/Gb3.[instrumentExt]"
if("Gn3") soundfile = "sound/[instrumentDir]/Gn3.[instrumentExt]"
if("G#3") soundfile = "sound/[instrumentDir]/G#3.[instrumentExt]"
if("Ab3") soundfile = "sound/[instrumentDir]/Ab3.[instrumentExt]"
if("An3") soundfile = "sound/[instrumentDir]/An3.[instrumentExt]"
if("A#3") soundfile = "sound/[instrumentDir]/A#3.[instrumentExt]"
if("Bb3") soundfile = "sound/[instrumentDir]/Bb3.[instrumentExt]"
if("Bn3") soundfile = "sound/[instrumentDir]/Bn3.[instrumentExt]"
if("B#3") soundfile = "sound/[instrumentDir]/B#3.[instrumentExt]"
if("Cb4") soundfile = "sound/[instrumentDir]/Cb4.[instrumentExt]"
if("Cn4") soundfile = "sound/[instrumentDir]/Cn4.[instrumentExt]"
if("C#4") soundfile = "sound/[instrumentDir]/C#4.[instrumentExt]"
if("Db4") soundfile = "sound/[instrumentDir]/Db4.[instrumentExt]"
if("Dn4") soundfile = "sound/[instrumentDir]/Dn4.[instrumentExt]"
if("D#4") soundfile = "sound/[instrumentDir]/D#4.[instrumentExt]"
if("Eb4") soundfile = "sound/[instrumentDir]/Eb4.[instrumentExt]"
if("En4") soundfile = "sound/[instrumentDir]/En4.[instrumentExt]"
if("E#4") soundfile = "sound/[instrumentDir]/E#4.[instrumentExt]"
if("Fb4") soundfile = "sound/[instrumentDir]/Fb4.[instrumentExt]"
if("Fn4") soundfile = "sound/[instrumentDir]/Fn4.[instrumentExt]"
if("F#4") soundfile = "sound/[instrumentDir]/F#4.[instrumentExt]"
if("Gb4") soundfile = "sound/[instrumentDir]/Gb4.[instrumentExt]"
if("Gn4") soundfile = "sound/[instrumentDir]/Gn4.[instrumentExt]"
if("G#4") soundfile = "sound/[instrumentDir]/G#4.[instrumentExt]"
if("Ab4") soundfile = "sound/[instrumentDir]/Ab4.[instrumentExt]"
if("An4") soundfile = "sound/[instrumentDir]/An4.[instrumentExt]"
if("A#4") soundfile = "sound/[instrumentDir]/A#4.[instrumentExt]"
if("Bb4") soundfile = "sound/[instrumentDir]/Bb4.[instrumentExt]"
if("Bn4") soundfile = "sound/[instrumentDir]/Bn4.[instrumentExt]"
if("B#4") soundfile = "sound/[instrumentDir]/B#4.[instrumentExt]"
if("Cb5") soundfile = "sound/[instrumentDir]/Cb5.[instrumentExt]"
if("Cn5") soundfile = "sound/[instrumentDir]/Cn5.[instrumentExt]"
if("C#5") soundfile = "sound/[instrumentDir]/C#5.[instrumentExt]"
if("Db5") soundfile = "sound/[instrumentDir]/Db5.[instrumentExt]"
if("Dn5") soundfile = "sound/[instrumentDir]/Dn5.[instrumentExt]"
if("D#5") soundfile = "sound/[instrumentDir]/D#5.[instrumentExt]"
if("Eb5") soundfile = "sound/[instrumentDir]/Eb5.[instrumentExt]"
if("En5") soundfile = "sound/[instrumentDir]/En5.[instrumentExt]"
if("E#5") soundfile = "sound/[instrumentDir]/E#5.[instrumentExt]"
if("Fb5") soundfile = "sound/[instrumentDir]/Fb5.[instrumentExt]"
if("Fn5") soundfile = "sound/[instrumentDir]/Fn5.[instrumentExt]"
if("F#5") soundfile = "sound/[instrumentDir]/F#5.[instrumentExt]"
if("Gb5") soundfile = "sound/[instrumentDir]/Gb5.[instrumentExt]"
if("Gn5") soundfile = "sound/[instrumentDir]/Gn5.[instrumentExt]"
if("G#5") soundfile = "sound/[instrumentDir]/G#5.[instrumentExt]"
if("Ab5") soundfile = "sound/[instrumentDir]/Ab5.[instrumentExt]"
if("An5") soundfile = "sound/[instrumentDir]/An5.[instrumentExt]"
if("A#5") soundfile = "sound/[instrumentDir]/A#5.[instrumentExt]"
if("Bb5") soundfile = "sound/[instrumentDir]/Bb5.[instrumentExt]"
if("Bn5") soundfile = "sound/[instrumentDir]/Bn5.[instrumentExt]"
if("B#5") soundfile = "sound/[instrumentDir]/B#5.[instrumentExt]"
if("Cb6") soundfile = "sound/[instrumentDir]/Cb6.[instrumentExt]"
if("Cn6") soundfile = "sound/[instrumentDir]/Cn6.[instrumentExt]"
if("C#6") soundfile = "sound/[instrumentDir]/C#6.[instrumentExt]"
if("Db6") soundfile = "sound/[instrumentDir]/Db6.[instrumentExt]"
if("Dn6") soundfile = "sound/[instrumentDir]/Dn6.[instrumentExt]"
if("D#6") soundfile = "sound/[instrumentDir]/D#6.[instrumentExt]"
if("Eb6") soundfile = "sound/[instrumentDir]/Eb6.[instrumentExt]"
if("En6") soundfile = "sound/[instrumentDir]/En6.[instrumentExt]"
if("E#6") soundfile = "sound/[instrumentDir]/E#6.[instrumentExt]"
if("Fb6") soundfile = "sound/[instrumentDir]/Fb6.[instrumentExt]"
if("Fn6") soundfile = "sound/[instrumentDir]/Fn6.[instrumentExt]"
if("F#6") soundfile = "sound/[instrumentDir]/F#6.[instrumentExt]"
if("Gb6") soundfile = "sound/[instrumentDir]/Gb6.[instrumentExt]"
if("Gn6") soundfile = "sound/[instrumentDir]/Gn6.[instrumentExt]"
if("G#6") soundfile = "sound/[instrumentDir]/G#6.[instrumentExt]"
if("Ab6") soundfile = "sound/[instrumentDir]/Ab6.[instrumentExt]"
if("An6") soundfile = "sound/[instrumentDir]/An6.[instrumentExt]"
if("A#6") soundfile = "sound/[instrumentDir]/A#6.[instrumentExt]"
if("Bb6") soundfile = "sound/[instrumentDir]/Bb6.[instrumentExt]"
if("Bn6") soundfile = "sound/[instrumentDir]/Bn6.[instrumentExt]"
if("B#6") soundfile = "sound/[instrumentDir]/B#6.[instrumentExt]"
if("Cb7") soundfile = "sound/[instrumentDir]/Cb7.[instrumentExt]"
if("Cn7") soundfile = "sound/[instrumentDir]/Cn7.[instrumentExt]"
if("C#7") soundfile = "sound/[instrumentDir]/C#7.[instrumentExt]"
if("Db7") soundfile = "sound/[instrumentDir]/Db7.[instrumentExt]"
if("Dn7") soundfile = "sound/[instrumentDir]/Dn7.[instrumentExt]"
if("D#7") soundfile = "sound/[instrumentDir]/D#7.[instrumentExt]"
if("Eb7") soundfile = "sound/[instrumentDir]/Eb7.[instrumentExt]"
if("En7") soundfile = "sound/[instrumentDir]/En7.[instrumentExt]"
if("E#7") soundfile = "sound/[instrumentDir]/E#7.[instrumentExt]"
if("Fb7") soundfile = "sound/[instrumentDir]/Fb7.[instrumentExt]"
if("Fn7") soundfile = "sound/[instrumentDir]/Fn7.[instrumentExt]"
if("F#7") soundfile = "sound/[instrumentDir]/F#7.[instrumentExt]"
if("Gb7") soundfile = "sound/[instrumentDir]/Gb7.[instrumentExt]"
if("Gn7") soundfile = "sound/[instrumentDir]/Gn7.[instrumentExt]"
if("G#7") soundfile = "sound/[instrumentDir]/G#7.[instrumentExt]"
if("Ab7") soundfile = "sound/[instrumentDir]/Ab7.[instrumentExt]"
if("An7") soundfile = "sound/[instrumentDir]/An7.[instrumentExt]"
if("A#7") soundfile = "sound/[instrumentDir]/A#7.[instrumentExt]"
if("Bb7") soundfile = "sound/[instrumentDir]/Bb7.[instrumentExt]"
if("Bn7") soundfile = "sound/[instrumentDir]/Bn7.[instrumentExt]"
if("B#7") soundfile = "sound/[instrumentDir]/B#7.[instrumentExt]"
if("Cb8") soundfile = "sound/[instrumentDir]/Cb8.[instrumentExt]"
if("Cn8") soundfile = "sound/[instrumentDir]/Cn8.[instrumentExt]"
if("C#8") soundfile = "sound/[instrumentDir]/C#8.[instrumentExt]"
if("Db8") soundfile = "sound/[instrumentDir]/Db8.[instrumentExt]"
if("Dn8") soundfile = "sound/[instrumentDir]/Dn8.[instrumentExt]"
if("D#8") soundfile = "sound/[instrumentDir]/D#8.[instrumentExt]"
if("Eb8") soundfile = "sound/[instrumentDir]/Eb8.[instrumentExt]"
if("En8") soundfile = "sound/[instrumentDir]/En8.[instrumentExt]"
if("E#8") soundfile = "sound/[instrumentDir]/E#8.[instrumentExt]"
if("Fb8") soundfile = "sound/[instrumentDir]/Fb8.[instrumentExt]"
if("Fn8") soundfile = "sound/[instrumentDir]/Fn8.[instrumentExt]"
if("F#8") soundfile = "sound/[instrumentDir]/F#8.[instrumentExt]"
if("Gb8") soundfile = "sound/[instrumentDir]/Gb8.[instrumentExt]"
if("Gn8") soundfile = "sound/[instrumentDir]/Gn8.[instrumentExt]"
if("G#8") soundfile = "sound/[instrumentDir]/G#8.[instrumentExt]"
if("Ab8") soundfile = "sound/[instrumentDir]/Ab8.[instrumentExt]"
if("An8") soundfile = "sound/[instrumentDir]/An8.[instrumentExt]"
if("A#8") soundfile = "sound/[instrumentDir]/A#8.[instrumentExt]"
if("Bb8") soundfile = "sound/[instrumentDir]/Bb8.[instrumentExt]"
if("Bn8") soundfile = "sound/[instrumentDir]/Bn8.[instrumentExt]"
if("B#8") soundfile = "sound/[instrumentDir]/B#8.[instrumentExt]"
if("Cb9") soundfile = "sound/[instrumentDir]/Cb9.[instrumentExt]"
if("Cn9") soundfile = "sound/[instrumentDir]/Cn9.[instrumentExt]"
else return
hearers(15, src) << sound(soundfile)
hearers(15, get_turf(instrumentObj)) << sound(soundfile)
/obj/structure/device/piano/proc/playsong()
do
/datum/song/proc/updateDialog(mob/user as mob)
instrumentObj.updateDialog() // assumes it's an object in world, override if otherwise
/datum/song/proc/shouldStopPlaying()
return !instrumentObj.anchored // add special cases to stop in subclasses
/datum/song/proc/playsong(mob/user as mob)
while(repeat >= 0)
var/cur_oct[7]
var/cur_acc[7]
for(var/i = 1 to 7)
cur_oct[i] = "3"
cur_acc[i] = "n"
for(var/line in song.lines)
for(var/line in lines)
//world << line
for(var/beat in text2list(lowertext(line), ","))
//world << "beat: [beat]"
var/list/notes = text2list(beat, "/")
for(var/note in text2list(notes[1], "-"))
//world << "note: [note]"
if(!playing || !anchored)//If the piano is playing, or is loose
if(!playing || shouldStopPlaying())//If the instrument is playing, or special case
playing = 0
return
if(lentext(note) == 0)
@@ -241,45 +239,49 @@
cur_oct[cur_note] = ni
playnote(uppertext(copytext(note,1,2)) + cur_acc[cur_note] + cur_oct[cur_note])
if(notes.len >= 2 && text2num(notes[2]))
sleep(song.tempo / text2num(notes[2]))
sleep(tempo / text2num(notes[2]))
else
sleep(song.tempo)
if(repeat > 0)
repeat-- //Infinite loops are baaaad.
while(repeat > 0)
sleep(tempo)
repeat--
if(repeat >= 0) // don't show the last -1 repeat
updateDialog(user)
playing = 0
updateUsrDialog()
repeat = 0
updateDialog(user)
/obj/structure/device/piano/attack_hand(var/mob/user as mob)
if(!anchored)
return
/datum/song/proc/interact(mob/user as mob)
var/dat = ""
usr.machine = src
var/dat = "<HEAD><TITLE>Piano</TITLE></HEAD><BODY>"
if(song)
if(song.lines.len > 0 && !(playing))
dat += "<A href='?src=\ref[src];play=1'>Play Song</A><BR><BR>"
dat += "<A href='?src=\ref[src];repeat=1'>Repeat Song: [repeat] times.</A><BR><BR>"
if(playing)
dat += "<A href='?src=\ref[src];stop=1'>Stop Playing</A><BR>"
dat += "Repeats left: [repeat].<BR><BR>"
if(lines.len > 0)
dat += "<H3>Playback</H3>"
if(!playing)
dat += "<A href='?src=\ref[src];play=1'>Play</A> <SPAN CLASS='linkOn'>Stop</SPAN><BR><BR>"
dat += "Repeat Song: "
dat += repeat > 0 ? "<A href='?src=\ref[src];repeat=-10'>-</A><A href='?src=\ref[src];repeat=-1'>-</A>" : "<SPAN CLASS='linkOff'>-</SPAN><SPAN CLASS='linkOff'>-</SPAN>"
dat += " [repeat] times "
dat += repeat < max_repeats ? "<A href='?src=\ref[src];repeat=1'>+</A><A href='?src=\ref[src];repeat=10'>+</A>" : "<SPAN CLASS='linkOff'>+</SPAN><SPAN CLASS='linkOff'>+</SPAN>"
dat += "<BR>"
else
dat += "<SPAN CLASS='linkOn'>Play</SPAN> <A href='?src=\ref[src];stop=1'>Stop</A><BR>"
dat += "Repeats left: <B>[repeat]</B><BR>"
if(!edit)
dat += "<A href='?src=\ref[src];edit=2'>Show Editor</A><BR><BR>"
dat += "<BR><B><A href='?src=\ref[src];edit=2'>Show Editor</A></B><BR>"
else
dat += "<A href='?src=\ref[src];edit=1'>Hide Editor</A><BR>"
dat += "<A href='?src=\ref[src];newsong=1'>Start a New Song</A><BR>"
dat += "<A href='?src=\ref[src];import=1'>Import a Song</A><BR><BR>"
if(song)
var/calctempo = (10/song.tempo)*60
dat += "Tempo : <A href='?src=\ref[src];tempo=10'>-</A><A href='?src=\ref[src];tempo=1'>-</A> [calctempo] BPM <A href='?src=\ref[src];tempo=-1'>+</A><A href='?src=\ref[src];tempo=-10'>+</A><BR><BR>"
var/linecount = 0
for(var/line in song.lines)
linecount += 1
dat += "Line [linecount]: [line] <A href='?src=\ref[src];deleteline=[linecount]'>Delete Line</A> <A href='?src=\ref[src];modifyline=[linecount]'>Modify Line</A><BR>"
dat += "<A href='?src=\ref[src];newline=1'>Add Line</A><BR><BR>"
dat += "<H3>Editing</H3>"
dat += "<B><A href='?src=\ref[src];edit=1'>Hide Editor</A></B>"
dat += " <A href='?src=\ref[src];newsong=1'>Start a New Song</A>"
dat += " <A href='?src=\ref[src];import=1'>Import a Song</A><BR><BR>"
var/calctempo = round(600 / tempo)
var/calcstep = tempo - 600 / (calctempo+1)
var/calcstep_b = tempo - 600 / (calctempo+10)
dat += "Tempo: <A href='?src=\ref[src];tempo=[calcstep_b]'>-</A><A href='?src=\ref[src];tempo=[calcstep]'>-</A> [calctempo] BPM <A href='?src=\ref[src];tempo=-[calcstep]'>+</A><A href='?src=\ref[src];tempo=-[calcstep_b]'>+</A><BR><BR>"
var/linecount = 0
for(var/line in lines)
linecount += 1
dat += "Line [linecount]: <A href='?src=\ref[src];modifyline=[linecount]'>Edit</A> <A href='?src=\ref[src];deleteline=[linecount]'>X</A> [line]<BR>"
dat += "<A href='?src=\ref[src];newline=1'>Add Line</A><BR><BR>"
if(help)
dat += "<A href='?src=\ref[src];help=1'>Hide Help</A><BR>"
dat += "<B><A href='?src=\ref[src];help=1'>Hide Help</A></B><BR>"
dat += {"
Lines are a series of chords, separated by commas (,), each with notes seperated by hyphens (-).<br>
Every note in a chord will play together, with chord timed by the tempo.<br>
@@ -292,121 +294,171 @@
A pause may be denoted by an empty chord: <i>C,E,,C,G</i><br>
To make a chord be a different time, end it with /x, where the chord length will be length<br>
defined by tempo / x: <i>C,G/2,E/4</i><br>
Combined, an example is: <i>E-E4/4,/2,G#/8,B/8,E3-E4/4</i>
Combined, an example is: <i>E-E4/4,F#/2,G#/8,B/8,E3-E4/4</i>
<br>
Lines may be up to 50 characters.<br>
A song may only contain up to 50 lines.<br>
"}
else
dat += "<A href='?src=\ref[src];help=2'>Show Help</A><BR>"
dat += "</BODY></HTML>"
user << browse(dat, "window=piano;size=700x300")
onclose(user, "piano")
dat += "<B><A href='?src=\ref[src];help=2'>Show Help</A></B><BR>"
/obj/structure/device/piano/Topic(href, href_list)
var/datum/browser/popup = new(user, "instrument", instrumentObj.name, 700, 500)
popup.set_content(dat)
popup.set_title_image(user.browse_rsc_icon(instrumentObj.icon, instrumentObj.icon_state))
popup.open()
if(!in_range(src, usr) || issilicon(usr) || !anchored || !usr.canmove || usr.restrained())
usr << browse(null, "window=piano;size=700x300")
onclose(usr, "piano")
/datum/song/Topic(href, href_list)
if(!in_range(instrumentObj, usr) || issilicon(usr) || !isliving(usr) || !usr.canmove || usr.restrained())
usr << browse(null, "window=instrument")
usr.unset_machine()
return
instrumentObj.add_fingerprint(usr)
if(href_list["newsong"])
song = new()
else if(song)
if(href_list["repeat"]) //Changing this from a toggle to a number of repeats to avoid infinite loops.
if(playing) return //So that people cant keep adding to repeat. If the do it intentionally, it could result in the server crashing.
var/tempnum = input("How many times do you want to repeat this piece? (max:10)") as num|null
if(tempnum > 10)
tempnum = 10
if(tempnum < 0)
tempnum = 0
repeat = round(tempnum)
lines = new()
tempo = 5 // default 120 BPM
name = ""
else if(href_list["tempo"])
song.tempo += round(text2num(href_list["tempo"]))
if(song.tempo < 1)
song.tempo = 1
else if(href_list["play"])
if(song)
playing = 1
spawn() playsong()
else if(href_list["newline"])
var/newline = html_encode(input("Enter your line: ", "Piano") as text|null)
if(!newline)
else if(href_list["import"])
var/t = ""
do
t = html_encode(input(usr, "Please paste the entire song, formatted:", text("[]", name), t) as message)
if(!in_range(instrumentObj, usr))
return
if(song.lines.len > 50)
return
if(lentext(newline) > 50)
newline = copytext(newline, 1, 50)
song.lines.Add(newline)
else if(href_list["deleteline"])
var/num = round(text2num(href_list["deleteline"]))
if(num > song.lines.len || num < 1)
return
song.lines.Cut(num, num+1)
if(lentext(t) >= 3072)
var/cont = input(usr, "Your message is too long! Would you like to continue editing it?", "", "yes") in list("yes", "no")
if(cont == "no")
break
while(lentext(t) > 3072)
else if(href_list["modifyline"])
var/num = round(text2num(href_list["modifyline"]),1)
var/content = html_encode(input("Enter your line: ", "Piano", song.lines[num]) as text|null)
if(!content)
return
if(lentext(content) > 50)
content = copytext(content, 1, 50)
if(num > song.lines.len || num < 1)
return
song.lines[num] = content
//split into lines
spawn()
lines = text2list(t, "\n")
if(copytext(lines[1],1,6) == "BPM: ")
tempo = 600 / text2num(copytext(lines[1],6))
lines.Cut(1,2)
else
tempo = 5 // default 120 BPM
if(lines.len > 50)
usr << "Too many lines!"
lines.Cut(51)
var/linenum = 1
for(var/l in lines)
if(lentext(l) > 50)
usr << "Line [linenum] too long!"
lines.Remove(l)
else
linenum++
updateDialog(usr) // make sure updates when complete
else if(href_list["stop"])
playing = 0
else if(href_list["help"])
help = text2num(href_list["help"]) - 1
else if(href_list["help"])
help = text2num(href_list["help"]) - 1
else if(href_list["edit"])
edit = text2num(href_list["edit"]) - 1
else if(href_list["edit"])
edit = text2num(href_list["edit"]) - 1
if(href_list["repeat"]) //Changing this from a toggle to a number of repeats to avoid infinite loops.
if(playing)
return //So that people cant keep adding to repeat. If the do it intentionally, it could result in the server crashing.
repeat += round(text2num(href_list["repeat"]))
if(repeat < 0)
repeat = 0
if(repeat > max_repeats)
repeat = max_repeats
else if(href_list["import"])
var/t = ""
do
t = html_encode(input(usr, "Please paste the entire song, formatted:", text("[]", src.name), t) as message)
if (!in_range(src, usr))
return
else if(href_list["tempo"])
tempo += text2num(href_list["tempo"])
if(tempo < 1)
tempo = 1
if(tempo > 600)
tempo = 600
if(lentext(t) >= 3072)
var/cont = input(usr, "Your message is too long! Would you like to continue editing it?", "", "yes") in list("yes", "no")
if(cont == "no")
break
while(lentext(t) > 3072)
else if(href_list["play"])
playing = 1
spawn()
playsong(usr)
//split into lines
spawn()
var/list/lines = text2list(t, "\n")
var/tempo = 5
if(copytext(lines[1],1,6) == "BPM: ")
tempo = 600 / text2num(copytext(lines[1],6))
lines.Cut(1,2)
if(lines.len > 50)
usr << "Too many lines!"
lines.Cut(51)
var/linenum = 1
for(var/l in lines)
if(lentext(l) > 50)
usr << "Line [linenum] too long!"
lines.Remove(l)
else
linenum++
song = new()
song.lines = lines
song.tempo = tempo
updateUsrDialog()
else if(href_list["newline"])
var/newline = html_encode(input("Enter your line: ", instrumentObj.name) as text|null)
if(!newline || !in_range(instrumentObj, usr))
return
if(lines.len > 50)
return
if(lentext(newline) > 50)
newline = copytext(newline, 1, 50)
lines.Add(newline)
add_fingerprint(usr)
updateUsrDialog()
else if(href_list["deleteline"])
var/num = round(text2num(href_list["deleteline"]))
if(num > lines.len || num < 1)
return
lines.Cut(num, num+1)
else if(href_list["modifyline"])
var/num = round(text2num(href_list["modifyline"]),1)
var/content = html_encode(input("Enter your line: ", instrumentObj.name, lines[num]) as text|null)
if(!content || !in_range(instrumentObj, usr))
return
if(lentext(content) > 50)
content = copytext(content, 1, 50)
if(num > lines.len || num < 1)
return
lines[num] = content
else if(href_list["stop"])
playing = 0
updateDialog(usr)
return
// subclass for handheld instruments, like violin
/datum/song/handheld
updateDialog(mob/user as mob)
instrumentObj.interact(user)
shouldStopPlaying()
return !isliving(instrumentObj.loc)
//////////////////////////////////////////////////////////////////////////
/obj/structure/device/piano
name = "space minimoog"
icon = 'icons/obj/musician.dmi'
icon_state = "minimoog"
anchored = 1
density = 1
var/datum/song/song
/obj/structure/device/piano/New()
song = new("piano", src)
if(prob(50))
name = "space minimoog"
desc = "This is a minimoog, like a space piano, but more spacey!"
icon_state = "minimoog"
else
name = "space piano"
desc = "This is a space piano, like a regular piano, but always in tune! Even if the musician isn't."
icon_state = "piano"
/obj/structure/device/piano/attack_hand(mob/user as mob)
interact(user)
/obj/structure/device/piano/interact(mob/user as mob)
if(!user || !anchored)
return
user.set_machine(src)
song.interact(user)
/obj/structure/device/piano/attackby(obj/item/O as obj, mob/user as mob)
if (istype(O, /obj/item/weapon/wrench))
if (anchored)