Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local durations={
- quarter=60/67
- }
- local globalOffset = -5
- durations.eighth = durations.quarter/2
- durations.sixteenth = durations.eighth/2
- durations.thirtysecond = durations.sixteenth/2
- durations.half = durations.quarter*2
- durations.whole = durations.half*2
- local pitches = { .5, .52973, .56122, .5946, .62995, .66741, .70709, .75, .7946, .84184, .8919, .94493, 1, 1.05946, 1.12246, 1.1892, 1.25991, 1.33482, 1.41419, 1.5, 1.58919, 1.68368, 1.7838, 1.88986, 2 }
- local notes = {
- C1=1,
- Db1=2,
- D1=3,
- Eb1=4,
- E1=5,
- F1=6,
- Gb1=7,
- G1=8,
- Ab1=9,
- A1=10,
- Bb1=11,
- B1=12,
- C2=13,
- Db2=14,
- D2=15,
- Eb2=16,
- E2=17,
- F2=18,
- Gb2=19,
- G2=20,
- Ab2=21,
- A2=22,
- Bb2=23,
- B2=24,
- C3=25
- }
- local intervals = {
- minor2=1,
- major2=2,
- minor3=3,
- major3=4,
- perfect4=5,
- tritone=6,
- perfect5=7,
- minor6=8,
- major6=9,
- minor7=10,
- major7=11,
- octave=12
- }
- local chords={
- maj={intervals.major3,intervals.minor3},
- min={intervals.minor3,intervals.major3},
- aug={intervals.major3,intervals.major3},
- dim={intervals.minor3,intervals.minor3},
- maj7={intervals.major3,intervals.minor3,intervals.major3},
- min7={intervals.minor3,intervals.major3,intervals.minor3},
- dom7={intervals.major3,intervals.minor3,intervals.minor3}
- }
- local speakers = {}
- function wrapSpeakers()
- speakers = {}
- for _,name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name) == "speaker" then
- table.insert(speakers,peripheral.wrap(name))
- end
- end
- end
- wrapSpeakers()
- local speaker = {}
- speaker.setSound = function(self,sound)
- self.sound = sound
- end
- speaker.play = function(self,note,duration,sound)
- if sound == nil then
- sound = self.sound
- end
- if sound ~= nil and #speakers >= 1 then
- speakers[1].playSound(sound,1,pitches[note+globalOffset])
- end
- sleep(duration)
- end
- speaker.playChord = function(self,rootNote,structure,duration,sound)
- if sound == nil then
- sound = self.sound
- end
- if sound ~= nil and #speakers >= 1 then
- speakers[1].playSound(sound,1,pitches[rootNote+globalOffset])
- local nextNote = rootNote
- local s = 2
- for _,interval in ipairs(structure) do
- nextNote = nextNote + interval
- if nextNote+globalOffset > 25 or s > #speakers then
- break
- end
- speakers[s].playSound(sound,1,pitches[nextNote+globalOffset])
- s = s + 1
- end
- end
- sleep(duration)
- end
- parallel.waitForAll(
- function()
- while true do
- local e = os.pullEvent()
- if e == "peripheral_detach" or e == "peripheral" then
- wrapSpeakers()
- end
- end
- end,
- function()
- speaker:setSound("rubber_duck:rubber_duck_use")
- while true do
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.eighth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.eighth)
- speaker:playChord(notes.E2,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.E2,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.E2,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.E2,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.E2,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.E2,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.E2,chords.dom7,durations.eighth)
- speaker:playChord(notes.D2,chords.maj7,durations.sixteenth)
- speaker:playChord(notes.D2,chords.maj7,durations.sixteenth)
- speaker:playChord(notes.D2,chords.maj7,durations.sixteenth)
- speaker:playChord(notes.D2,chords.maj7,durations.sixteenth)
- speaker:playChord(notes.D2,chords.maj7,durations.sixteenth)
- speaker:playChord(notes.D2,chords.maj7,durations.sixteenth)
- speaker:playChord(notes.D2,chords.maj7,durations.eighth)
- speaker:playChord(notes.A1,chords.maj7,durations.eighth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.eighth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.eighth)
- speaker:playChord(notes.E2,chords.dom7,durations.eighth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.eighth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.sixteenth)
- speaker:playChord(notes.B1,chords.dom7,durations.eighth)
- speaker:playChord(notes.A1,chords.maj7,durations.eighth)
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement