All, I am trying to make a simple piano app for fun. Just to mess with audio and multitouch.
However, when I execute the code below, it crashes everywhere - the simulator, the IOS simulator, and the ipad itself. Anything I am missing here? The “ui” I am requiring is the exact same lua file from the MultitouchButton sample code. Note: if I comment out the “system.activate (“multitouch”)” line it works fine but I can only touch one key at a time. Note 2: I even commented out the playing of the audio thinking that was the issue. No dice.
----------------------
-- IMPORTS
----------------------
local ui = require ("ui")
system.activate( "multitouch" )
----------------------
-- VARIABLES
----------------------
local imagepath = "assets/images/piano/"
local whiteKeys = {
"EBkey","DGAkey","DGAkey","CFkey","EBkey","DGAkey","CFkey"
}
local keyX = 16
local whiteKeyHeight = 90
local whiteKeyStartY = 160
local blackKeyYs = { 220, 310, 400, 580, 670 }
----------------------
-- Display Groups
----------------------
local primaryGroup = display.newGroup()
------------------
-- Tables
------------------
------------------
-- Display Objects
------------------
local background = display.newRect (0,0,display.contentWidth, display.contentHeight)
background:setFillColor (255, 0, 0, 255)
background:setReferencePoint ( display.TopCenterReferencePoint )
background.x = display.contentWidth / 2
background.y = 0
primaryGroup:insert (background)
------------------
-- Audio Objects
------------------
local audiopath = "assets/audio/"
local bnote = audio.loadSound (audiopath.."BNote.mp3")
local anote = audio.loadSound (audiopath.."ANote.mp3")
local gnote = audio.loadSound (audiopath.."GNote.mp3")
local fnote = audio.loadSound (audiopath.."FNote.mp3")
local enote = audio.loadSound (audiopath.."ENote.mp3")
local dnote = audio.loadSound (audiopath.."DNote.mp3")
local cnote = audio.loadSound (audiopath.."CNote.mp3")
local ashnote = audio.loadSound (audiopath.."ASharpNote.mp3")
local gshnote = audio.loadSound (audiopath.."GSharpNote.mp3")
local fshnote = audio.loadSound (audiopath.."FSharpNote.mp3")
local dshnote = audio.loadSound (audiopath.."DSharpNote.mp3")
local cshnote = audio.loadSound (audiopath.."CSharpNote.mp3")
local noteAudio = {
bnote, anote, gnote, fnote, enote, dnote, cnote, ashnote, gshnote, fshnote, dshnote, cshnote
}
--====================================================================--
-- Keys
--====================================================================--
------------------
-- Functions
------------------
local function onKeyReleased ( event )
--if (audio.isChannelPlaying (event.id) ) then
-- audio.stop (noteAudio[event.id], {channel = event.id, loops = 0})
--end
end
local function onKeyPressed ( event )
--audio.play (noteAudio[event.id], {channel = event.id, loops = 0})
end
------------------
-- UI
------------------
-- White Keys
for i=1, 7 do
local keyBtn = ui.newButton {
default = imagepath..whiteKeys[i]..".png",
over = imagepath..whiteKeys[i].."\_pressed.png",
onPress = onKeyPressed,
onRelease = onKeyReleased,
id = i
}
keyBtn:setReferencePoint ( display.TopLeftReferencePoint )
keyBtn.x = keyX
keyBtn.y = whiteKeyStartY + (whiteKeyHeight \* (i-1))
primaryGroup:insert ( keyBtn )
end
-- Black Keys
for j=1, 5 do
local keyBtn = ui.newButton {
default = imagepath.."Blackkey.png",
over = imagepath.."Blackkey\_pressed.png",
onPress = onKeyPressed,
onRelease = onKeyReleased,
id = 7+j
}
keyBtn:setReferencePoint ( display.TopLeftReferencePoint )
keyBtn.x = keyX
keyBtn.y = blackKeyYs[j]
primaryGroup:insert ( keyBtn )
end
--====================================================================--
-- BUTTONS
--====================================================================--
--====================================================================--
-- INITIALIZE
--====================================================================--
local initVars = function ()
------------------
-- Inserts
------------------
------------------
-- Reference Points
------------------
--triangle:setReferencePoint( display.CenterReferencePoint )
------------------
-- Positions
------------------
------------------
-- Colors
------------------
------------------
-- Alignment
------------------
------------------
-- Alpha
------------------
------------------
-- Tables
------------------
------------------
-- Listeners
------------------
end -- end initVars ()
--=========================================================
initVars()
-----------------------------------------------------------
-- Function: cleanSounds
-- Inputs: none
-- Outputs: none
-- Purpose: Stops any sounds playing and disposes them
-----------------------------------------------------------
local cleanSounds = function()
end -- end cleanSounds()
-----------------------------------------------------------
--=========================================================
-- Function: clean
-- Inputs: none
-- Outputs: none
-- Purpose: Performs cleanup for the view. The director will
-- clean up the visuals contained within the primary
-- group. This function will handle anything else
--=========================================================
clean = function()
--Runtime:removeEventListener( "enterFrame", monitorMem )
cleanSounds()
end -- end clean()
--=========================================================
-- MUST return a display.newGroup()
return primaryGroup
end -- end new()
--=========================================================
Thanks!
Christian [import]uid: 69863 topic_id: 21305 reply_id: 321305[/import]
[import]uid: 52491 topic_id: 21305 reply_id: 84371[/import]