SHOW:
|
|
- or go back to the newest paste.
| 1 | -- DECLARING | |
| 2 | local mn = peripheral.wrap("back")
| |
| 3 | local mnn = peripheral.wrap("top")
| |
| 4 | local spk = peripheral.find("speaker")
| |
| 5 | -- FUNCTIONS | |
| 6 | ||
| 7 | local function clear() | |
| 8 | mn.clear() | |
| 9 | end | |
| 10 | local function setTextColor(clr) | |
| 11 | mn.setTextColor(clr) | |
| 12 | end | |
| 13 | local function setCursorPos(x,y) | |
| 14 | mn.setCursorPos(x,y) | |
| 15 | end | |
| 16 | local function setBackgroundColor(clr) | |
| 17 | mn.setBackgroundColor(clr) | |
| 18 | end | |
| 19 | local function write(txt) | |
| 20 | mn.write(txt) | |
| 21 | end | |
| 22 | local function playNote(sound,vol,ptc) | |
| 23 | spk.playNote(sound,vol,ptc) | |
| 24 | end | |
| 25 | local function Nclear() | |
| 26 | mnn.clear() | |
| 27 | end | |
| 28 | local function NsetTextColor(clr) | |
| 29 | mnn.setTextColor(clr) | |
| 30 | end | |
| 31 | local function NsetCursorPos(x,y) | |
| 32 | mnn.setCursorPos(x,y) | |
| 33 | end | |
| 34 | local function NsetBackgroundColor(clr) | |
| 35 | mnn.setBackgroundColor(clr) | |
| 36 | end | |
| 37 | local function Nwrite(txt) | |
| 38 | mnn.write(txt) | |
| 39 | end | |
| 40 | local sx,sy = mn.getSize() | |
| 41 | local octabeL = 12 | |
| 42 | local octaveC = 6 | |
| 43 | local octave = {0,1,0,1,0,0,1,0,1,0,1,0}
| |
| 44 | local notes = {"C", "#","D", "#","E","F","#","G","#","A","#","H"}
| |
| 45 | local swf = 0 | |
| 46 | for i=1,sx do | |
| 47 | for g=1,sy do | |
| 48 | if (g == 1) then | |
| 49 | setBackgroundColor(colors.brown) | |
| 50 | else | |
| 51 | setBackgroundColor(colors.white) | |
| 52 | end | |
| 53 | setCursorPos(i,g) | |
| 54 | write(" ")
| |
| 55 | end | |
| 56 | if (swf == 1) then | |
| 57 | swf = 0 | |
| 58 | else | |
| 59 | swf = 1 | |
| 60 | end | |
| 61 | end | |
| 62 | local color = 0 | |
| 63 | local startingY = 1 | |
| 64 | local startingX = 1 | |
| 65 | for o=1,octaveC do | |
| 66 | setCursorPos(startingX, startingY) | |
| 67 | --print("SX"..startingX.." | SY: "..startingY.."O: "..o )
| |
| 68 | for i=1,octabeL do | |
| 69 | color = octave[i] | |
| 70 | if (color == 1) then | |
| 71 | setCursorPos(startingX + i-1, startingY + 1) | |
| 72 | setBackgroundColor(colors.black) | |
| 73 | for h=1,2 do | |
| 74 | setCursorPos(startingX + i-1, startingY + 1 + h) | |
| 75 | if (h == 1) then | |
| 76 | write(" ")
| |
| 77 | setCursorPos(startingX + i-1, startingY + 1 + h-1) | |
| 78 | setBackgroundColor(colors.black) | |
| 79 | setTextColor(colors.black) | |
| 80 | write(notes[i]) | |
| 81 | setCursorPos(startingX + i-1, startingY + 1 + h) | |
| 82 | setBackgroundColor(colors.black) | |
| 83 | else | |
| 84 | write(" ")
| |
| 85 | end | |
| 86 | end | |
| 87 | else | |
| 88 | setBackgroundColor(colors.white) | |
| 89 | setTextColor(colors.white) | |
| 90 | local px, py = mn.getCursorPos() | |
| 91 | setCursorPos(px,2) | |
| 92 | write(notes[i]) | |
| 93 | end | |
| 94 | setCursorPos(startingX + i, startingY) | |
| 95 | end | |
| 96 | startingY = 1 | |
| 97 | startingX = 1 | |
| 98 | startingX = startingX + (octabeL * o) | |
| 99 | end | |
| 100 | local instrument = "harp" | |
| 101 | --123 | |
| 102 | local nsx,nsy = mnn.getSize() | |
| 103 | NsetBackgroundColor(colors.white) | |
| 104 | Nclear() | |
| 105 | function drawBT(colorm, txt, line) | |
| 106 | NsetBackgroundColor(colorm) | |
| 107 | NsetCursorPos(1,line) | |
| 108 | for i=1,7 do | |
| 109 | NsetBackgroundColor(colorm) | |
| 110 | for g=1,2 do | |
| 111 | Nwrite(" ")
| |
| 112 | end | |
| 113 | NsetCursorPos(1+i,line) | |
| 114 | end | |
| 115 | NsetCursorPos(1,line) | |
| 116 | Nwrite(txt) | |
| 117 | ||
| 118 | local lastWrite = nil | |
| 119 | local waitTime = nil | |
| 120 | end | |
| 121 | -- write to notesheet | |
| 122 | function writeToNotes(name, pitch) | |
| 123 | local file = fs.open("disk/"..name, "r")
| |
| 124 | local txt = file.readAll() | |
| 125 | file.close() | |
| 126 | local file = fs.open("disk/"..name, "w")
| |
| 127 | if (lastWrite ~= nil) then | |
| 128 | waitTime = os.time() *50 - lastWrite | |
| 129 | else | |
| 130 | waitTime = 1 | |
| 131 | end | |
| 132 | file.write(txt..pitch.."-"..waitTime.."-"..instrument.." ") | |
| 133 | file.close() | |
| 134 | lastWrite = os.time() * 50 | |
| 135 | end | |
| 136 | -- end func | |
| 137 | ||
| 138 | -- recs screen | |
| 139 | function drawRSC() | |
| 140 | NsetBackgroundColor(colors.white) | |
| 141 | Nclear() | |
| 142 | local recsf = fs.open("disk/recs", "r")
| |
| 143 | local recsn = recsf.readAll() | |
| 144 | recsf.close() | |
| 145 | print(recsn) | |
| 146 | for i=1,tonumber(recsn) do | |
| 147 | if (tonumber(recsn) < 4) then | |
| 148 | NsetCursorPos(i,1) | |
| 149 | elseif (tonumber(recsn) < 7) then | |
| 150 | NsetCursorPos(i,2) | |
| 151 | elseif tonumber(recsn) < 10 then | |
| 152 | NsetCursorPos(i,3) | |
| 153 | end | |
| 154 | NsetBackgroundColor(colors.green) | |
| 155 | NsetTextColor(colors.white) | |
| 156 | Nwrite(tostring(i)) | |
| 157 | end | |
| 158 | NsetCursorPos(1,nsy) | |
| 159 | NsetBackgroundColor(colors.blue) | |
| 160 | NsetTextColor(colors.white) | |
| 161 | Nwrite("back")
| |
| 162 | end | |
| 163 | -- end | |
| 164 | drawBT(colors.green, "Record",1) | |
| 165 | drawBT(colors.blue, "Recs",2) | |
| 166 | drawBT(colors.orange, "Instrs",4) | |
| 167 | drawBT(colors.brown, "Hide",5) | |
| 168 | --123 | |
| 169 | local recState = false | |
| 170 | local recName = nil | |
| 171 | local screen = 1 | |
| 172 | while (true) do | |
| 173 | event, side, xPos, yPos = os.pullEvent("monitor_touch")
| |
| 174 | if (side == "back") then | |
| 175 | if (yPos > 1) then | |
| 176 | local noteMBR = xPos | |
| 177 | if (xPos > 12 and xPos < 24) then | |
| 178 | noteMBR = noteMBR - octabeL | |
| 179 | elseif (xPos > 23) then | |
| 180 | noteMBR = (noteMBR - (octabeL *2)) | |
| 181 | end | |
| 182 | if (xPos == 24) then | |
| 183 | noteMBR = 1 | |
| 184 | end | |
| 185 | print(noteMBR.." | "..xPos) | |
| 186 | if (string.find(notes[noteMBR], "#")) then | |
| 187 | playNote(instrument, 1, xPos-1+0.5) | |
| 188 | if (recState) then | |
| 189 | writeToNotes(tostring(recName), xPos-1+0.5) | |
| 190 | end | |
| 191 | for j=2,4 do | |
| 192 | setCursorPos(xPos,j) | |
| 193 | setBackgroundColor(colors.gray) | |
| 194 | write(" ")
| |
| 195 | end | |
| 196 | os.sleep(0.2) | |
| 197 | for j=2,4 do | |
| 198 | setCursorPos(xPos,j) | |
| 199 | setBackgroundColor(colors.black) | |
| 200 | write(" ")
| |
| 201 | end | |
| 202 | else | |
| 203 | if (recState) then | |
| 204 | writeToNotes(tostring(recName), xPos-1) | |
| 205 | end | |
| 206 | playNote(instrument, 1, xPos-1) | |
| 207 | for j=2,5 do | |
| 208 | setCursorPos(xPos,j) | |
| 209 | setBackgroundColor(colors.lightGray) | |
| 210 | write(" ")
| |
| 211 | end | |
| 212 | os.sleep(0.2) | |
| 213 | for j=2,5 do | |
| 214 | setCursorPos(xPos,j) | |
| 215 | setBackgroundColor(colors.white) | |
| 216 | write(" ")
| |
| 217 | end | |
| 218 | end | |
| 219 | end | |
| 220 | elseif (side == "top") then | |
| 221 | if (screen == 1) then | |
| 222 | if (yPos == 1) then | |
| 223 | if (recState == true) then | |
| 224 | recState = false | |
| 225 | drawBT(colors.green, "Record",1) | |
| 226 | else | |
| 227 | recState = true | |
| 228 | local recsf = fs.open("disk/recs", "r")
| |
| 229 | local recsn = recsf.readAll() | |
| 230 | recsf.close() | |
| 231 | local recsf = fs.open("disk/recs", "w")
| |
| 232 | recsf.write(tostring(tonumber(recsn) + 1)) | |
| 233 | recsf.close() | |
| 234 | recName = tonumber(recsn) + 1 | |
| 235 | lastWrite = os.time()*50 | |
| 236 | local recfile = fs.open("disk/"..tostring(recName), "w")
| |
| 237 | recfile.close() | |
| 238 | drawBT(colors.red, "STOP",1) | |
| 239 | end | |
| 240 | elseif (yPos == 2) then | |
| 241 | drawRSC() | |
| 242 | screen = 2 | |
| 243 | elseif (yPos == 4) then | |
| 244 | screen =3 | |
| 245 | NsetBackgroundColor(colors.white) | |
| 246 | Nclear() | |
| 247 | if (instrument == "harp") then | |
| 248 | drawBT(colors.orange, "Piano",1) | |
| 249 | drawBT(colors.red, "Guitar",2) | |
| 250 | drawBT(colors.red, "Cowbell",3) | |
| 251 | elseif (instrument == "guitar") then | |
| 252 | drawBT(colors.red, "Piano",1) | |
| 253 | drawBT(colors.orange, "Guitar",2) | |
| 254 | drawBT(colors.red, "Cowbell",3) | |
| 255 | elseif (instrument == "cowbell") then | |
| 256 | drawBT(colors.red, "Piano",1) | |
| 257 | drawBT(colors.red, "Guitar",2) | |
| 258 | drawBT(colors.orange, "Cowbell",3) | |
| 259 | else | |
| 260 | drawBT(colors.red, "Piano",1) | |
| 261 | drawBT(colors.red, "Guitar",2) | |
| 262 | drawBT(colors.red, "Cowbell",3) | |
| 263 | end | |
| 264 | drawBT(colors.blue, "back",5) | |
| 265 | elseif (yPos == 5) then | |
| 266 | screen = 4 | |
| 267 | setBackgroundColor(colors.brown) | |
| 268 | clear() | |
| 269 | NsetBackgroundColor(colors.brown) | |
| 270 | Nclear() | |
| 271 | end | |
| 272 | elseif (screen == 2) then | |
| 273 | if (yPos == 5 and xPos < 6) then | |
| 274 | screen =1 | |
| 275 | NsetBackgroundColor(colors.white) | |
| 276 | Nclear() | |
| 277 | drawBT(colors.green, "Record",1) | |
| 278 | drawBT(colors.blue, "Recs",2) | |
| 279 | drawBT(colors.orange, "Instrs",4) | |
| 280 | drawBT(colors.brown, "Hide",5) | |
| 281 | else | |
| 282 | local rec = fs.open("disk/"..xPos, "r")
| |
| 283 | local recN = rec.readAll() | |
| 284 | local wait = nil | |
| 285 | local noteN = nil | |
| 286 | local instrName = nil | |
| 287 | rec.close() | |
| 288 | line = {} --Define a empty table for our words
| |
| 289 | for word in string.gmatch(recN, "%S+") do --We go thru the string word by word ("%w+") and give one word at a time the value word
| |
| 290 | local ii = 1 | |
| 291 | for wordd in string.gmatch(word, "[^-]+") do | |
| 292 | print(tonumber(wordd)) | |
| 293 | if (ii == 2) then | |
| 294 | wait = tonumber(wordd) | |
| 295 | elseif (ii==3) then | |
| 296 | instrName = wordd | |
| 297 | else | |
| 298 | print("NOTE")
| |
| 299 | noteN = tonumber(wordd) | |
| 300 | end | |
| 301 | ii = ii + 1 | |
| 302 | end | |
| 303 | print("wait secs:"..wait)
| |
| 304 | print("note: "..noteN)
| |
| 305 | print("RECORDING: "..xPos.." | NOTE: "..noteN.." WAITTIME: "..wait)
| |
| 306 | playNote(instrName,1,tonumber(noteN)) | |
| 307 | local waitTimeinSeconds = wait | |
| 308 | os.sleep(tonumber(waitTimeinSeconds)) | |
| 309 | end --end our for loop | |
| 310 | end | |
| 311 | elseif (screen == 3) then | |
| 312 | if (yPos == 1) then | |
| 313 | instrument = "harp" | |
| 314 | elseif (yPos == 2) then | |
| 315 | instrument = "guitar" | |
| 316 | elseif (yPos == 3) then | |
| 317 | instrument = "cow_bell" | |
| 318 | end | |
| 319 | screen =1 | |
| 320 | NsetBackgroundColor(colors.white) | |
| 321 | Nclear() | |
| 322 | drawBT(colors.green, "Record",1) | |
| 323 | drawBT(colors.blue, "Recs",2) | |
| 324 | drawBT(colors.orange, "Instrs",4) | |
| 325 | drawBT(colors.brown, "Hide",5) | |
| 326 | end | |
| 327 | end | |
| 328 | end |