function init() mode(1) setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00) piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" } notes = {"C ", "C#", "D ", "D#", "E ", "F ", "F#", "G ", "G#", "A ", "A#", "B "} pnotes = {"c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"} vcolor = { 1, 9, 5, 4, 6, 12, 14, 15} piano_pos=18 mousewait=0 compas = 0 compasos = {} volumens = {} volum = 4 tempo = 4 for i=0,1279 do compasos[i] = 108 end for i=0,1279 do volumens[i] = 4 end compasos[0] = 49 compasos[1] = 49 compasos[2] = 49 compasos[7] = 50 compasos[8] = 50 compasos[9] = 50 compasos[10] = 50 old_mouse_x,old_mouse_y = 0,0 message_count = 255 message_text = " HOLA" end function update() color(COLOR_WHITE, COLOR_BLACK) cls() ink(COLOR_BLACK) for i=0,39 do if (i==compas) then paper(COLOR_LIGHT_RED) else paper(COLOR_LIGHT_GRAY) end print("___\003",(i%10)*4,flr(i/10)+5) end if mousebutton(1) and mousey()<=8 and mousey()>=5 then compas = flr(mousex()/4)+(mousey()-5)*10 end for i=0,11 do local k = 11-i local pos = ((piano_pos+i)%12)+1 local oct = flr((piano_pos+i)/12)+1 color(COLOR_WHITE, COLOR_BLACK) print(notes[pos], 1, 10+k) color(COLOR_BLACK, COLOR_WHITE) print(piano[pos], 3, 10+k) color(COLOR_BLACK, COLOR_LIGHT_GRAY+flr(oct%2)) print("_______\003_______\003_______\003_______\003", 8, 10+k) color(COLOR_BLACK, oct) if pos==6 then print(tostr(oct), 0, 10+k) else print(" ", 0, 10+k) end end piano_pos = mid(0, piano_pos+mousewheel(), 96) if mousewait>0 then mousewait=mousewait-1 end if mousebutton(1) and mousewait==0 then if mousex()<8 and mousey()>=10 and mousey()<=21 then local note = piano_pos+(11-(mousey()-10)) play("l4o"..tostr(note/12)..pnotes[(note%12)+1]) mousewait=10 end end for i=0,31 do local n = compasos[(compas*32)+i] if n>=piano_pos and n<=piano_pos+11 then if i>0 and n~=compasos[(compas*32)+i-1] then local oct = flr(n/12)+1 color(COLOR_BLACK, COLOR_LIGHT_GRAY+flr(oct%2)) print("\003",7+i,10+11-(n-piano_pos)) end color(COLOR_BLACK,vcolor[volumens[(compas*32)+i]]) if i==31 or compasos[(compas*32)+i+1]~=n then print("\003",8+i,10+11-(n-piano_pos)) else print("_",8+i,10+11-(n-piano_pos)) end end end if mousex()>=8 and mousey()>=10 and mousey()<=21 then if mousebutton(1) then volumens[(compas*32)+mousex()-8] = volum compasos[(compas*32)+mousex()-8] = piano_pos+11-(mousey()-10) if old_mouse_x ~= mousex() or old_mouse_y ~= mousey() then local note = piano_pos+11-(mousey()-10) play("l4v"..volum.."o"..tostr(note/12)..pnotes[(note%12)+1]) end old_mouse_x,old_mouse_y = mousex(),mousey() else old_mouse_x,old_mouse_y = 0,0 if mousebutton(3) then compasos[(compas*32)+mousex()-8] = 108 end end end if btnp(KEY_RETURN) then if btn(KEY_LSHIFT) then play_song(true) else play_song() end end if btn(KEY_LCTRL) and btnp(KEY_S) then local song = prepare_song(true) toclipboard(song) show_message("SAVED TO CLIPBOARD") end -- if btn(KEY_LSHIFT) and btnp(KEY_L) then -- local song = prepare_song(true) -- toclipboard(song) -- show_message("SAVED TO CLIPBOARD") -- end color(15,0)print("VOLUM:",0,0) color(1,0)print("\143",0,1) color(9,0)print("\143",1,1) color(5,4)print("\143",2,1) color(4,0)print("\143",3,1) color(6,0)print("\143",4,1) color(12,0)print("\143",5,1) color(14,0)print("\143",6,1) color(15,0)print("\143",7,1) color(15,0)print("\244",volum-1,2) if mousex()<8 and mousey()==1 and mousebutton(1) then volum = mousex()+1 end if not mousedown and mousex()==20 and mousey()==1 and mousebutton(1) and tempo > 0 then tempo = tempo - 1 mousedown = true end if not mousedown and mousex()==24 and mousey()==1 and mousebutton(1) and tempo < 9 then tempo = tempo + 1 mousedown = true end if mousedown and not mousebutton(1) then mousedown = false end color(15,0)print("TEMPO",20,0) print("\247 0 \246",20,1) print(tostr(tempo),22,1) if message_count > 0 then message_color = 15 if message_count < 18 then message_color = message_count>>1 end color(message_color,0)print(message_text,0,26) message_count = message_count - 1 end end function show_message(text) message_count = 255 message_text = text end function search_song_end() local i = 1279 while i>0 and compasos[i] == 108 do i=i-1 end return i+1 end function play_song(entire_song) local song = prepare_song(entire_song) log(song) play(song) end function prepare_song(entire_song) entire_song = entire_song or false local note_size = {1,2,3,4,6,8,12,16,24,32} local note_names = {"c","c#","d", "d#","e","f","f#","g","g#","a","a#","b"} local song = "" local current_note = 255 local current_octave = 4 local current_volume = 4 local p=compas*32 local ends=32+compas*32 if tempo ~= 4 then song = "t"..tostr(tempo) end if entire_song then p=0 ends=search_song_end() end while p0 do local i=1 while d>note_size[i] do i=i+1 end if note_size[i]>d then i=i-1 end d=d-note_size[i] if current_length~=i-1 then current_length = i-1 song=song.."l"..tostr(i-1) end if o<9 then song=song..note else song=song.."r" end end end return song end