Advertisement
fyrkantis

Instrument

Nov 2nd, 2024 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. volume = 3.0
  2. speaker = peripheral.find("speaker")
  3. instrument = "pling"
  4. keyInstruments = {
  5.     [keys.h]="harp",
  6.     [keys.j]="pling",
  7.     [keys.k]="chime",
  8.     [keys.l]="iron_xylophone",
  9.     [keys.b]="bass",
  10.     [keys.n]="guitar",
  11.     [keys.m]="banjo",
  12.     [keys.comma]="didgeridoo",
  13.     [keys.period]="bit"
  14. }
  15.  
  16. keyNotes = {[keys.one]=0, [keys.q]=1, [keys.two]=2, [keys.w]=3, [keys.three]=4, [keys.e]=5, [keys.r]=6, [keys.five]=7, [keys.t]=8, [keys.six]=9, [keys.y]=10, [keys.u]=11, [keys.eight]=12, [keys.i]=13, [keys.nine]=14, [keys.o]=15, [keys.zero]=16, [keys.p]=17, [keys.z]=18, [keys.s]=19, [keys.x]=20, [keys.d]=21, [keys.c]=22, [keys.v]=23, [keys.g]=24}
  17.  
  18. noteNames = {[0]="F#3", "G3", "G#3", "A3", "A#3", "B3", "C4", "C#4", "D4", "D#4", "E4", "F4", "F#4", "G4", "G#4", "A4", "A#4", "B4", "C5", "C#5", "D5", "D#5", "E5", "F5", "F#5"}
  19.  
  20. shell.run("clear")
  21. print("Switch instrument with \"HJKLBNM,.\"")
  22.  
  23. while true do
  24.     local event, key, isHeld = os.pullEvent("key")
  25.     if keyNotes[key] ~= nil then
  26.         speaker.playNote(instrument, volume, keyNotes[key])
  27.         print(noteNames[keyNotes[key]])
  28.     elseif keyInstruments[key] ~= nil then
  29.         instrument = keyInstruments[key]
  30.         print("Instrument: "..instrument)
  31.         print("HJKLBNM,.")
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement