Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MUSIC with BEGIN STORAGE (CPC) #1075

Closed
poppichicken opened this issue Dec 9, 2024 · 9 comments
Closed

MUSIC with BEGIN STORAGE (CPC) #1075

poppichicken opened this issue Dec 9, 2024 · 9 comments
Labels
wontfix This will not be worked on

Comments

@poppichicken
Copy link

hi Marco.

BEGIN STORAGE "disk1"
    MUSIC "examples_scale.mid" AS "scale.dat"
ENDSTORAGE

BITMAP ENABLE(320,200,4)
COLOR BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

DIM mus AS MUSIC
DLOAD "scale.dat" TO VARPTR(mus)

No doubt i'm doing something wrong, but the DLOAD command seems to be crashing the CPC.

@poppichicken
Copy link
Author

I've also tried:

mus=NEW MUSIC(1024)
DLOAD "scale.dat" TO VARPTR(mus)

But that crashes the CPC as well.

@spotlessmind1975 spotlessmind1975 added wontfix This will not be worked on documentation Improvements or additions to documentation labels Dec 9, 2024
@spotlessmind1975
Copy link
Owner

Hi @poppichicken and thank you for your bug report!

No doubt i'm doing something wrong, but the DLOAD command seems to be crashing the CPC.

Actually there is no crash: simply, since there is no MUSIC command, no music is played. It would be necessary to use this command. However, this would not be enough: in fact, since the length of the song is not indicated with the DIM ... AS MUSIC command, by default it is 0 and therefore no music will be played.

To solve it, it is necessary to allocate enough space to hold the MIDI song converted to the IMF format. At the moment, unfortunately, there is no instruction that returns the length of the generated file (and the IDE does not provide this type of detail), and therefore it is necessary to go by trial and error.

Try this code:

BEGIN STORAGE "disk1"
    MUSIC "scale.mid" AS "scale.dat"
ENDSTORAGE

BITMAP ENABLE(320,200,4)
COLOR BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

mus = NEW MUSIC( 512 )
DLOAD "scale.dat" TO VARPTR(mus)

MUSIC mus

Thank you again!

@poppichicken
Copy link
Author

Thanks Marco.
Unfortunately (regardless of which value I try for the size parameter of NEW MUSIC), the CPC crashes.

BEGIN STORAGE "disk1"
    MUSIC "examples_scale.mid" AS "scale.dat"
ENDSTORAGE

BITMAP ENABLE(320,200,4)
COLOR BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

mus = NEW MUSIC(1024)
DLOAD "scale.dat" TO VARPTR(mus)

MUSIC mus

Here is the .mid file I'm using (zipped so that github would allow me to attach it to this ticket):

examples_scale.zip

@spotlessmind1975
Copy link
Owner

spotlessmind1975 commented Dec 10, 2024

Hi @poppichicken , thank you for the feedback!

Your example doesn't crash.

This is the audio produced:

image

@poppichicken
Copy link
Author

poppichicken commented Dec 12, 2024

That's odd.
I just can't get it to work properly.

BEGIN STORAGE "disk1"
    MUSIC "examples_scale.mid" AS "scale.dat"
ENDSTORAGE

BITMAP ENABLE(320,200,4)
COLOR BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

PRINT"BEFORE"

mus = NEW MUSIC(512)
'DLOAD "scale.dat" TO VARPTR(mus)
'MUSIC mus

PRINT"AFTER"

Does this:

image

However if I uncomment the DLOAD command:

DLOAD "scale.dat" TO VARPTR(mus)

Some weird things happen on screen.
The colours change, the mode briefly changes, and then it stops like this:

image

Uncommenting the MUSIC command:

MUSIC mus

Does this:

image

But this time the scale music does play.
So it looks like it is indeed working, which tells me that something is messing with the firmware.

[EDIT]

I tried moving the DLOAD command before the screen commands:

BEGIN STORAGE "disk1"
    MUSIC "examples_scale.mid" AS "scale.dat"
ENDSTORAGE

mus = NEW MUSIC(512)
DLOAD "scale.dat" TO VARPTR(mus)

BITMAP ENABLE(320,200,4)
COLOR BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

PRINT"BEFORE"
MUSIC mus
PRINT"AFTER"

And that worked nicely!
(the music played as well)

image

@spotlessmind1975
Copy link
Owner

Hi @poppichicken , thank you for the feedback!

The colours change, the mode briefly changes, and then it stops like this:
I tried moving the DLOAD command before the screen commands:

The colour change and strange side effect depend by the ticket #1035 .

But this time the scale music does play.

So it works... does it?

@poppichicken
Copy link
Author

Ah yes of course, #1035 does indeed explain the issue.
My apologies, I forgot about that.

With this code, the scale example works.

BEGIN STORAGE "disk1"
    MUSIC "examples_scale.mid" AS "scale.dat"
ENDSTORAGE

mus = NEW MUSIC(512)
DLOAD "scale.dat" TO VARPTR(mus)

BITMAP ENABLE(320,200,4)
COLOR BORDER WHITE
CLS BLACK
DEFINE KEYBOARD ASYNC

PRINT"BEFORE"
MUSIC mus
PRINT"AFTER"

@spotlessmind1975 spotlessmind1975 removed the documentation Improvements or additions to documentation label Dec 13, 2024
@spotlessmind1975
Copy link
Owner

spotlessmind1975 commented Dec 13, 2024

Hi @poppichicken , I'm happy to let you know that the command FILE SIZE has been added, to obtain (at compile time) the size of the file added inside the storage. It will be made available with the next COLDFIX/BETA.

@poppichicken
Copy link
Author

That's a great feature.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants