Hey, @dave1707…
First off, thank you very much for the above code example. Sometimes I’m blind to the simplest of solutions.
And second, I hope I copied your modfied code back in properly without loosing the formatting. Kinda new at this.
As you can see I have made some mods to your code. By removing the sharps the result places the notes on the musical staff in the correct position. I’ll deal with those later.
I plan on developing this more but using a different methodology for selecting the notes. I will share after I get that going.
As for the other example you mentioned above that allows you to “move a cursor left or right and insert or delete notes” I’d be interested in seeing that.
Once again, thank you very much.
P.S. I’m in my late 50’s and just now learning to read sheet music.
-- Musical Notes V1
--[[
NOTES:
This code is the work of Dave1707 and modified by me, Scotty. I added the G-Clef, as a sprite, at his direction. The symbol can be had at " https://pixabay.com/images/search/treble clef/ ".
Most modifications and additions to Dave's code are noted below.
--]]
displayMode(FULLSCREEN)
function setup()
-- To locate size and vertical loc of the G-Clef symbol.
parameter.integer("hGClef", 50,200,120)
parameter.integer("wGClef", 50,200, 75)
parameter.integer("yGClef",-25, 25, 2)
dx=0
btnTab={}
--nameTab={"c","#c","d","#d","e","f","#f","g","#g","a","#a","b"}
-- All "sharpened" notes have been removed for now.
-- If the note is sharp it still needs to reside at the same position on the music staff.
-- For now lets not worry about them.
nameTab={"C","D","E","F","G","A","B","c","d","e","f","g","a","b"}
z=0
for x=1,7 do -- columns
for y=1,2 do -- rows
z=z+1
btnTab[z]=button(x*125, 200-y*60, nameTab[z], z)
end
end
keyTab={}
marginL = 20
marginR = 0
end
function draw()
background(219, 217, 219, 255)
lines()
for z=1,#nameTab do
btnTab[z]:draw()
end
end
function lines()
fill(0)
stroke(0)
strokeWidth(2)
yLine=500
size=16
for d=0,4 do
-- 5-line staff
line(dx+marginL,d*size+yLine,WIDTH-marginR,d*size+yLine)
-- Left hand vertical line of 5-line staff
for d=0,3 do
line(dx+marginL,d*size+yLine,dx+marginL,d*size+yLine+size)
end
end
pushMatrix()
translate(60,0)
for z=1,#keyTab do
s=keyTab[z]
pushMatrix()
translate(z*40+dx, s*size/2+yLine-24)
-- Add leadger lines when notes falls above or below 5-line staff.
if nameTab[s] == "C" or nameTab[s] == "a" then
line(-12,0, 12,0)
elseif nameTab[s] == "b" then
line(-12,-size/2, 12,-size/2)
end
rotate(30) -- Notes on sheetmusic are rotated just a bit for style.
--ellipse(z*30+dx,s*size/2+yLine-24,16,10) -- Moved x,y loc to translate op
ellipse(0,0,20,15)
popMatrix()
line(z*40+7+dx,s*8+yLine-24,z*40+7+dx,s*8+yLine+50-24) -- note stem
text(nameTab[s],z*40+dx,yLine-35)
end
popMatrix()
sprite("Dropbox:G_Clef",dx+marginL+40,yGClef+yLine+26,wGClef,hGClef)
end
function touched(t)
if t.y>200 then
if t.state==MOVING then
dx=dx+t.deltaX
end
else
if t.state==BEGAN and t.y<HEIGHT/2 then
for z=1,#nameTab do
btnTab[z]:touched(t)
end
end
end
end
button=class()
function button:init(x,y,n,k)
self.x=x
self.y=y
self.name=n
self.key=k
end
function button:draw()
sprite("Cargo Bot:Dialogue Button",self.x,self.y)
fill(255)
text(self.name,self.x,self.y)
end
function button:touched(t)
if t.x>self.x-49 and t.x<self.x+49 and t.y>self.y-23 and t.y<self.y+23 then
table.insert(keyTab,self.key)
end
end