Music tool WIP
This commit is contained in:
@@ -10,7 +10,7 @@ function init()
|
||||
mousewait=0
|
||||
compas = 0
|
||||
compasos = {}
|
||||
for i=0,31 do compasos[i] = 108 end
|
||||
for i=0,1279 do compasos[i] = 108 end
|
||||
compasos[0] = 49
|
||||
compasos[1] = 49
|
||||
compasos[2] = 49
|
||||
@@ -25,6 +25,16 @@ 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
|
||||
@@ -55,25 +65,25 @@ function update()
|
||||
end
|
||||
|
||||
for i=0,31 do
|
||||
local n = compasos[i]
|
||||
local n = compasos[(compas*32)+i]
|
||||
if n>=piano_pos and n<=piano_pos+11 then
|
||||
if i>0 and n~=compasos[i-1] 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,COLOR_LIGHT_RED)
|
||||
if i==31 or compasos[i+1]~=n then
|
||||
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
|
||||
compasos[mousex()-8] = piano_pos+11-(mousey()-10)
|
||||
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("l4o"..tostr(note/12)..pnotes[(note%12)+1])
|
||||
@@ -82,12 +92,18 @@ function update()
|
||||
else
|
||||
old_mouse_x,old_mouse_y = 0,0
|
||||
if mousebutton(3) then
|
||||
compasos[mousex()-8] = 108
|
||||
compasos[(compas*32)+mousex()-8] = 108
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if btnp(KEY_RETURN) then play_song() end
|
||||
if btnp(KEY_RETURN) then
|
||||
if btn(KEY_LSHIFT) then
|
||||
play_song(true)
|
||||
else
|
||||
play_song()
|
||||
end
|
||||
end
|
||||
|
||||
color(15,0)print("\143",0,0)
|
||||
color(14,0)print("\143",1,0)
|
||||
@@ -101,18 +117,33 @@ function update()
|
||||
|
||||
end
|
||||
|
||||
function play_song()
|
||||
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)
|
||||
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 p=0
|
||||
while p<32 do
|
||||
|
||||
local p=compas*32
|
||||
local ends=32+compas*32
|
||||
|
||||
if entire_song then
|
||||
p=0
|
||||
ends=search_song_end()
|
||||
end
|
||||
|
||||
while p<ends do
|
||||
current_note = compasos[p]
|
||||
local d=0
|
||||
while current_note == compasos[p] do d=d+1 p=p+1 end
|
||||
while d<32 and current_note == compasos[p] do d=d+1 p=p+1 end
|
||||
local o = flr(current_note/12)
|
||||
if o<9 and current_octave~=o then
|
||||
current_octave=o
|
||||
@@ -136,5 +167,6 @@ function play_song()
|
||||
end
|
||||
end
|
||||
end
|
||||
log(song)
|
||||
play(song)
|
||||
end
|
||||
Reference in New Issue
Block a user