Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

ABCplayerCodea - play music in your project



  • Posts: 141

    @Fred thanks! And very good point about iExplorer. Just because Codea can't have project sharing, doesn't mean we can't do it ourselves...

  • Posts: 141

    @Fred BTW its not a big deal for what you are doing, but Lua's string concatenation operator .. can be a little slow.

    So if you have a lot of strings to join together, instead of doing this:

    foo = 'X:1\n'
        ..'T:Bogg Blues\n'
        ..'C:Fred Bogg\n'

    Do this:

    bar = {
        'T:Bogg Blues',
        'C:Fred Bogg',
    foo = table.join(bar, "\n");

    Now as I say in your case you aren't joining that many strings and it is only being done once. But you may find this way easer to read (I know I do).

    A Note On Performance: Premature optimization is the root of all evil. So don't get too obsessed about things like the ..operator in general. If you are joining a relatively small number of strings, or doing it just once, it doesn't matter much in the grand scheme of things.

    However if you are joining a lot of strings, or doing it in a loop (so it all adds up), etc; then consider using table.insert() followed by a table.join().

  • Posts: 384

    Thanks @JockM, I recently discovered I could put the whole tune in text brackets like this:

    [[X: 1
    T: Bogg Blues]]

    So that will save a lot of typing those .. concatenations, and removes the need to escape certain characters.

    Your point in the efficiency is right though, I am thinking of moving to a table approach for the main parsing of the tune because a lot of string operations are involved, and cumulatively they are taking too long.

  • Posts: 141

    @Fred Question for you:

    In my — probably Quixotic — quest to implement Codea's sound APIs in LoveCodea, I came across a line in ABCPlayer that threw me for a loop:

    sound(DATA, sound( ENCODE, soundTable ),gnNoteVolume*(gnMasterVolume+gnMasterVolumeModifier))

    Now sound(DATA,{base64string}is documented in the codea help, but sound(ENCODE, {tableOfSettings}is not.

    From context I believe what is going on is: take a table of sound parameters an then convert them to base64. Is this correct?

  • Posts: 384

    Hi @JockM, yes, that's right. I didn't realise that wasn't documented - TLL made it to fix issues with precision and caching that I came across when beta testing Cargo-Bot and developing the (equally Quixotic) music player. :)

    @Simeon, another thing to add to the docs... and this ENCODE API is still so useful - thanks @Dylan I think it was who did it.

  • Posts: 141

    @Fred Excellent, thank you!

    I fear a full implementation of sound()really is quixotic. the non-PCM portions of sound are so deeply reliant on SFXR that it would require either making a custom version of Löve2D with SFXR embedded in it, or rewriting SFXR (~1,400 lines of C++) in Lua.

    Each approach has rather large negatives, as you can imagine.

    So right now I am trying to find if there is a reasonable subset of sound's generative capabilities I could implement. But to do that I have to know everything sound can do :)

    On the plus side I do have soundBuffer()fully implemented...

  • Posts: 384

    Great, @JockM, I would love to try Love again. You know what we also need, is a good demo exploration of what soundbuffer() can do. I have dabbled, but still don't understand it properly.

  • edited June 2012 Posts: 141

    @Fred I may try and see if I can't write something to show offsoundBuffer() it is one of those functions that seems so innocent, and at first the documentation seems obvious... until you start to dig in and realize that there are a lot of assumptions that are undocumented. I spent most of yesterday just working out

    • big endian vs little endian
    • signed vs unsigned
    • does soundBuffer() add to what is played or replace what is played

    I also plan to write a small utility to convert PCM data into Lua strings, because it is a royal PITA to do it right now :)

  • Posts: 266

    this is crashing on me. I'm pretty sure I copied the files correctly because I did it twice. I wanna use music in my project but I don't wanna have to do it through xcode. can this music player play a mp3 file I download from a royalty free website

  • Posts: 384

    Hi @veeeralp, what iPad are you using? When did it crash and what was on the screen? It won't play an mp3.

  • edited August 2012 Posts: 437

    Hey. Do I need to create the instruments of the song?
    I am trying to play this song file converted from MIDI with MidiZyx2abc_1.08:

    But it echoes this error:

    error: error: [string "--ABCMusic class by Fred Bogg..."]:166: attempt to perform arithmetic on local 'denominator' (a nil value)

    I am using the ABCMusic class version from CargoBot in Codea 1.4.3
    Thanks for this great tool!

  • Posts: 384

    Hi @juaxix, thanks! I'm looking through your tune now and have got parts of it going. Watch this space.

    First thing, try using the most recent version which can be found on GitHub at the link at the top of the thread. It has got the ability to change sounds, but rudimentary.

    You can avoid escape codes by using double square brackets to enclose the tune text.

    And it would be best to replace the \n characters with new lines.

    The different instruments will need extracting, as I haven't fully implemented multivoicing.

    I'll post again when it's working with your tune!

  • Posts: 437

    Have you thought of a simple series of regular expressions to format the text that the conversor prints?

  • Posts: 266

    @Fred I'm using an iPad 2 16 GB. It crashed when it said loading on the screen and the delta time freezes at 0.04 seconds. I'm probably just copying it wrong. Any help?

  • Posts: 384

    Hi @juaxix, yes, I have listed them in the thread above somewhere, but you won't need to escape the ' if you use double square brackets.

  • Posts: 384

    Hi @veeeralp, does it freeze ? How long did you let it run for? The default song is quite long...

  • Posts: 384

    Wow @juaxix, that tune is very complex. I've made a few changes as a result, but it will be a while until I get it playing nicely.

  • edited August 2012 Posts: 384

    Double post deleted.

  • edited August 2012 Posts: 437

    Wow thanks you for all the effort!...dont take it so serious, it is just a test, the midi comes from a movie...

  • Posts: 384

    That's ok, it's a way of extending it and fixing bugs! By the way, in the MidiZyx thing you should tell it what key the music is in, otherwise when we try to play it the notes are wrong. When I changed the key to A rather than C it began to be recognisable... :)

  • Posts: 384

    Now I recognise it, @juaxix, it's the one where the boat sinks, right? :) I changed the key to E and the wrong notes went away. That's the bit in your ABC tune that starts with K:

    The code on GitHub (see top of thread) will now play at least the piano bit ok. The problem is the ABC tune output from MIDIzyx2ABC is a bit mangled. Not all MIDI Files convert well. For multiple voicing, you will need to break each bit out and put them as separate tunes. Play them simultaneously with different instruments like I demonstrate in Main().

    Thanks for the challenge, but I admit there is a long way to go before this works easily... :)

  • Posts: 1,255

    I think I'm being incredibly dense here, but I'm having trouble wrangling ABCMusicPlayer. I tried looking through the code in CargoBot as an example, but in that project the music player has been wrappered in additional classes, and a good chunk seems to have been commented out. I'm having trouble with just the basics of feeding the class and playing a tune within the structure of a program.

    Is there a simple example program that shows how to add a music player, initialize a tune, set the various values for LOOP, etc?

    Thanks for all your work in this. I can see that it's not an easy piece of code by any measure.

  • Posts: 520

    Dont know it is any help, but I ripped out the note calculations from the player for a project I started on. The idea was using physical objects that was created by sound, but haven't done much more than a small animation.

  • Posts: 1,255

    Thanks, @tnlogy, that's helpful in seeing how the notes are shaped, and I think it'll help me in some of my sound effects.

    But I'd still like to see a program that just creates an instance of ABCMusic, loads in a tune, and plays it back. I can't even figure out what the range of values is for some of the required init fields (LOOP, for example). I know it should be dead obvious, and probably is if I wasn't looking at it with the wrong set of preconcieved ideas, but it's just not clear to me where to begin.

  • Posts: 1,255

    Hang on... the version of ABCMusic I was using was the one from CargoBot, which appears to have been modded to meet the needs of that code. Looking at the original gist, the code looks much more straightforward and the comments inform me of the values needed.

    I should have been smart enough to head for the gist earlier. My apologies.

  • Posts: 384

    Hi @Mark, yes it was developed beyond what was used in CargoBot, so the GitHub version should be easier to start with. Granted, the code is a bit of a mess. :) LOOP should be a 1 or 0 flag to determine whether to loop the tune. Has been a long time since I looked at te code though! Let me know how you go, I would be more than happy to return to it if you need. Cheers!

  • Posts: 1,255

    Can anyone recommend a nice app on the Mac (or better yet, iPad) for composing ABC format music? I'm putting the final touches on a game for the store, and the biggest remaining task is a couple of original background tunes.

  • Posts: 384

    I found MidiZyx2abc was the best. You can either start with a MIDI file or type the score out in ABC format. It will convert it to traditional score as you go which is good if you read music. Complex MIDI files do not always convert nicely... But if you have one you love let me now and I can give you a hand.

  • Posts: 2,043

    @Fred, in your opinion, what's the best ABC composing software for PC?

  • Posts: 384

    Hi @JakAttak, unfortunately I've only tried the mac ones, but luckily the one I like above is written in Java, so you could also run it in Windows. If you've tried other forms of composition software, you will find it rather primitive. :)

  • Posts: 2,043

    @Fred Instead of using something like that I decided to just write it in ABCPlayer so I was wondering if it is possible to clear the Project cache so that my changes will be reflected every time?

  • Posts: 384

    Hi @JakAttak, yes I think there is a flag we can change to reload and cache the tune every time. I'll try to find it what it is called.

  • edited July 2013 Posts: 2,043

    Thanks! ABCPlayer is great by the way.

Sign In or Register to comment.