I'm amazed how easy and quick it is to make a useful program for my iPad using smart Basic!
- Dav
Code: Select all
'Basic metronome
'Flashes and ticks.
'by Dav, FEB/2015
'for ipad or iphone
'you can adjust tempo, bmp, flash, tick
'default settings for metronome
tempo= 120
meter=4
flash=1
tick=1
'setup screen
text
set output font color 1,1,1
set output back color 0,128/255,128/255
set buttons font name "Verdana"
set output font size "76"
set buttons font size "28"
'make objects
slider "tempo" value tempo/240 at 3,100 size 300
switch "flash" state 1 at 50,70
switch "tick" state 1 at 170,70
'make buttons
button "tempo" text "Tempo: "&str$(tempo) at 20,150
button "bpm" text "BPM: "& str$(meter) at 20,220
button "+" text "+" at 190,220
button "-" text "-" at 150,220
'start tick at beat 1
metercount=1
do
if metercount=1 then
'flash on beat 1 if flash on
if flash = 1 then
'flash...
set output back color 1,1,0
pause .02
'back to normal
set output back color 0,128/255,128/255
end if
'tick high on beat 1 if tick on
if tick=1 then
notes set "115:c6"
notes play
end if
else
'back to normal color on other beats
if flash = 1 then
set output back color 0,128/255,128/255
end if
'lower tick on other beats
if tick=1 then
notes set "115:c4"
notes play
end if
end if
'display beat info
text clear
print "Beat:"&metercount
print "* ^";
'raise beat count here
metercount = metercount+1
if metercount > meter then metercount=1
'change tempo..
if slider_changed("tempo") then
newtempo=int(240*slider_value("tempo"))
'don't allow under 20
if newtempo > 20 then
button "tempo" set text "Tempo: "&str$(newtempo)
tempo=newtempo
end if
end if
'raise bpm...
if button_pressed("+") then
'only allow 12 bpm
if meter < 12 then
meter = meter + 1
button "bpm" set text "BPM: "& str$(meter)
end if
end if
'lower bpm
if button_pressed("-") then
'dont go below 1
if meter > 1 then
meter = meter - 1
button "bpm" set text "BPM: "& str$(meter)
end if
end if
'turn flash on/off
if switch_changed("flash") then
if switch_state("flash") = 1 then
flash= 1
else
flash= 0
end if
end if
'turn tick on/off
if switch_changed("tick") then
if switch_state("tick") = 1 then
tick = 1
else
tick = 0
end if
end if
'Tick delay routine below...
'we added a small pause to flash screen.
'So here we compensate for that..
if flash = 1 then
'only do after 1st flashing beat
'we added .02, so we subtract here
if metercount=1 then
pause (60 / tempo) -.02
else
pause 60 / tempo
end if
else
pause 60 / tempo
end if
until forever