Skip to content

Instantly share code, notes, and snippets.

@fredbogg
Created January 27, 2012 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredbogg/1686325 to your computer and use it in GitHub Desktop.
Save fredbogg/1686325 to your computer and use it in GitHub Desktop.
ABCplayerCodea v0.2.1
-- ABCplayerCodea version 0.2.0
-- Plays ABC musical notation format tunes on the Codea/Codify iPad platform. 
-- By Fred Bogg, November 2011.  Improvements welcome. Thanks to ipda41001 for coding assistance.
-- This program defines musical notes and chords, parses an ABC format tune, creates a table
-- of notes to be played with their durations, and then plays it.  With the parsing done 
-- first, playback is possible without slowing down draw frames (psuedo-background).
-- 0.2.0
-- Uses new sound() API based on sfxr
-- Tunes can play independently
-- made tempo independent for each tune
-- parses comments
-- 0.1.9
-- bug fixes and stuff
-- 0.1.7
-- Added flats
-- Implemented key signatures
-- Improved parsing of rendered MIDI files
-- 0.1.6
-- New sharps
-- Starting to implement key signatures
-- Improvements to pattern matching
-- 0.1.5
-- Put class functions in separate tab, data in separate table.
-- Crazily moved tempo iparameter to createSoundTable() to set default to the tune tempo. 
-- Added loop argument to ABCMusic. 
-- 0.1.4
-- added fromTheTop() (a rewind)
-- added demo touched function to demo fromTheTop()
-- 0.1.3
-- Added sharps to central octave.
-- Use this function to perform your initial setup
function setup()
    
    -- loads data into ABCtune string variable
    sampleMusic()
    -- Instantiates the class using the tune. arg 1 for loop, arg 2 for debug, arg 3 dumps
    myTune = ABCMusic(ABCtune)
    
  --[[ secondTune = ABCMusic('X:1\n'
    ..'T:Pac Man Theme\n'
    ..'C:Toshio Kai arr. Fred Bogg Copyright NAMCO\n'
    ..'Q:135\n'
    ..'M:4/4\n'
    ..'L:1/16\n'
    ..'K:C\n'
    ..'[B,B]b^f[B^d] b/2^f3/2^dB [C,C]c\'g[Ce] c\'/2g3/2[Ce]C|\n'
    ..'[B,B]b^f[B^d] b/2^f3/2^dB ^d/2e/2[^gf]f/2^f/2[^ag]g/2^g/2ab2')
    --]]
end   
-- This function gets called once every frame
function draw()    
    
    -- Just a test draw; insert our game here... :)
    ellipse(CurrentTouch.x,CurrentTouch.y,100)
    
    -- Play the next bit of music, not the whole lot 
    myTune:play()
 --  secondTune:play()
end
function touched(touch)
    if touch.state == BEGAN then
        myTune:fromTheTop()
    end 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment