ABCplayerCodea - play music in your project

It’s really really good !!!
I have write a part of a music from stanley myers :

Cavatina =
'X:1

…'T:Cavatina

…‘C:Stanley Myers

…‘Q:60

…‘M:3/4

…‘L:1/8

…‘K:E major

…’[E2b]BegeB | [D2b]BdgdB | [C2a/2] b/2 [Ac\‘2] cecA | F,AcecA | ’
…’[B,2a/2] b/2 [Ac\‘2] cecA | B,FAdA [Fb/2] a/2 | [E,b2]DGBGD | E,B =d g =d [Ba/2] g/2 |’
…’[A,g] cegec | [=Df]Acfc[AA/2] e/2 | [=G,f]B=df=dB | [=Ce]=GBeB=G | [F,e]AcecA |’
…’ B,E[Af]c[Ad]F | [E,4Ae4]FGFGB | e4’

But if you look a good Midi to abc converter, it’s better :slight_smile:

Hi Hyro, that’s a nice tune! You know I really liked your game that you posted recently, do you plan to add some music?

I’m still working on improvements to the program, which should be ready for another update soon.

I’ve been using a MIDI to ABC converter called MidiZyx2abc, which you learn more about at:

http://www.midicond.de/Freeware/MidiZyx2abc_EnglishManual.html

Thanks ! And yes, I will create and add music in my game :smiley:
And thanks again for MidiZyx2abc !

New version copied and pasted in one page on github:

https://gist.github.com/1971776

.codea file on Posterous:

http://fredbogg.posterous.com/abcplayercodea-v04

This version (still lots of work to do!) adds caching support to ensure your sounds are buffered for lag-free animation.

Cool! Thanks.

In case anyone is using MidiZyx2abc to make ABC files from MIDI files, you might want to use these regular expressions to prepare the file for pasting in to Codea as a variable…

I’ve been using a web-based RegEx thing at http://gskinner.com/RegExr/

This one adds the escape character \ in front of the apostrophes that denote higher octaves:

Pattern: /([a-g’])'/gxsm

Replace: $1\’

If you care about how long the lines get, use this to ‘word wrap’, it puts a newline character after every 40 - 80 characters, depending on chord endings and bar lines:

Pattern: /(\[.{40,80}?\]\s?\|?\s?)/gxm

Replace: $1\

Then use this one, it adds …’ to start and
’ to end of a line:

Pattern: /^^\.\.\'[^\
']$/gxsm

Replace: …'$&\

New version with experimental sound changer and better note sustain.

https://gist.github.com/2782181

or for beta users: http://fredbogg.posterous.com/abcplayercodea-v043-71112

Thanks to @MdMbunny, @Codeslinger and @KMEB I have incorporated some improvements, but still a long way to go… ! Next plan is to implement multi voicing as per the ABC standard.

@Fred have you considered creating a traditional GitHub project for this? That way I could just directly fork it or do a clone

Hi @JockM, I looked into it briefly and settled on gist as a lightweight alternative. If it would encourage collaboration I could be convinced to move to a project. If you’ve looked at the code you will know I’m not a software engineer… :slight_smile: so I would benefit from some help. Some questions:

Can I manage it from the iPad?
Will it make it easier to incorporate changes?
Is it much more overhead?

Over the last few evenings I have been working on restructuring the class, reducing global namespace pollution (thanks!), and adding multivoicing and different instrument sounds. I will look in to GitHub again and perhaps start my next version there.

Well if you make it a full GitHub project you can have an issue tracker, and a wiki for documentation. People can also watch the project and be notified if there are changes.

Its also a bit handier for people who are using the Codea Run Time producing something for the App Store.

Ok folks, @JockM has convinced me to manage it as a GitHub project, so from now on I will be updating it at: https://github.com/fredbogg/ABCplayerCodea

I found that, in conjunction with iExplorer, it is fairly easy to upload and download the project files this way.

@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…

@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\
'
    ..'T:Bogg Blues\
'
    ..'C:Fred Bogg\
'
    ..'Q:1/8=240\
'
    ..'M:12/8\
'
    ..'L:1/8\
'

Do this:

bar = {
	'T:Bogg Blues',
	'C:Fred Bogg',
	'Q:1/8=240',
	'M:12/8',
	'L:1/8',
}

foo = table.join(bar, "\
");

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().

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.

@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?

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. :slight_smile:

@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.

@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 :slight_smile:

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

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.

@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 :slight_smile:

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