Larry Deack

unread,
Jan 13, 2018, 1:37:02 AM1/13/18
to MIT App Inventor Forum
Midi files (.mid) are not being played correctly. Setting a minimum time does not like mp3s.

 I have twelve 80 byte single note (halfnote at 60bpm exported from Musescore)

  I call sound.play for a midi when I get a click so just the two pieces of "code" for each button. It works fine for a while but then one of the notes will stop playing and then another and sometimes a note will distort and like the notes that stop playing it stays that way. This is an extremely easy test to duplicate. Is this a known issue?

 Mp3s do not seem to go bonkers but they make static clicking sounds between notes and are they are 20k bytes. This seems to be very limiting for making music apps that play notes as the user plays them and the lag/click between notes ( I edited mp3s to make sure the waves started immediately). I was impressed by App Inventor at first but as a musician this is not even as good as bit banging the speaking on an Apple II.

Any feedback or workaround would be nice otherwise I have to use some other tool. I can play .mid files using other Android Apps. I am using Windows 10 and android 7.0.

Chris Ward

unread,
Jan 13, 2018, 6:16:53 AM1/13/18
to MIT App Inventor Forum
Hello Larry

Attach your Project file (.aia) so that we can see what is going on.

Larry Deack

unread,
Jan 13, 2018, 12:31:37 PM1/13/18
to MIT App Inventor Forum
So, it's not a known issue? OK here is the test project. It is just 24 buttons and 12 .mid files and the code is just the handler calling the sound so...
midiplaytest.aia

Chris Ward

unread,
Jan 13, 2018, 2:17:28 PM1/13/18
to MIT App Inventor Forum
Hi Larry

Ok, I have tested your test app on two devices, Lenovo A816 [Android 4.4.4] and Samsung Galaxy Note 3 [Android 5.0], and tested the files on Windows7 64 with two applications.

.mp3 files are not fit for this purpose and it really shows in your app with .mid files side-by-side.

On both of the Android devices, the .mid files play as expected and over a period of five minutes, I could not reproduce the issues you report - however, I disabled the .mp3 sounds before compiling the app. 

It's not important because the .mid files are the way to go, but c53.mp3 made my Windows Media Player crash when played in a loop!

So, what device are you using? It seems that it could be something external to the app that is causing the issues you are experiencing. Possibly interruptions by an Anti-Virus app? Device in power-save mode?

Unstable memory: Could be caused by the failure of any app, including your test. Most common is a browser fault brought about by a non-compliant web page, which in the case of Chrome is often hidden from the User. If you use a news site a lot, that could easily be the culprit.

Power-down the device and leave it switched-off for at least a minute, switch it back on and ensure that your app is the first to be selected. I also find it helps if there is no internet connection because behind-the-scenes updates (Google, grrr) can have a negative effect on any app.




Larry Deack

unread,
Jan 13, 2018, 2:59:55 PM1/13/18
to MIT App Inventor Forum
Thank you Chris so much for the very rapid response. I will try it and see. My first real try at a real app for a friend uses the timer to play long sequences of notes and it starts skipping some after a some random amount of time. I did reboot the device but did not leave it off. It got confused at one point failing to load AppInventor so I rebooted both the Windows 10 laptop and the Galaxy S7 I am using and was fine but the skipped notes still happens. Funny that the mp3s die in a loop. I think I made the mp3s using some phone app I downloaded. 

I'd really like to be able to change the midi mapping so it can be any sound but I have no idea how or if that can be done.

Thanks again, it really helps to talk to somebody else.

 

Chris Ward

unread,
Jan 13, 2018, 4:33:57 PM1/13/18
to MIT App Inventor Forum
Hi Larry

I'd really like to be able to change the midi mapping so it can be any sound but I have no idea how or if that can be done.

That can be done in the code, you can have a list of sound files, select from that list, assign it to a Sound Component.

Larry Deack

unread,
Jan 13, 2018, 4:57:27 PM1/13/18
to MIT App Inventor Forum
I understand that I can play lists of sounds and have created lists of buttons and other components passed around in globals, but I am talking about the midi mapping of what instrument gets play when the midi file calls for instrument number XXXX. Basically I want to change the instrument that plays. This is normal for people who use midi apps. Are you familiar with the midi specification? Ultimately controlling MIDI devices with a cell phone would be a really fun toy for many of my friends who play midi devices.

This was supposed to be a quick app to help a friend but I also wanted to see if I could use App Inventor to talk to my Esp32 projects and my CNC machine. I was hoping to use App Inventor to help musicians and our local Arduino/Pi maker group in Orange County California so I may be post and appreciate the help.

Chris Ward

unread,
Jan 13, 2018, 7:56:56 PM1/13/18
to MIT App Inventor Forum
Hi Larry

I roughly understand what it is you want to achieve though I am not a musician and my wife has banned me from singing anywhere at anytime (with good reason!). The .mid files would probably need to be saved in uncompressed ASCII format. A large file though might require an extension to AI in order to read it quickly.

Concerning Arduino and App Inventor, there is a lot of activity, search this forum.





Larry Deack

unread,
Jan 13, 2018, 9:04:16 PM1/13/18
to MIT App Inventor Forum
Chris,

  As a music and math teacher you have no idea how often I hear that, and how much they hate math.

The ascii idea is interesting. I see some C code that converts ascii to midi and ascii to midi for a command line utility. Not sure how that would work to "code" it in app inventor but if I was coding in C...

 This is a new environment for me. Back in the 90s I wrote printer drivers for Windows in C so I am used to getting access to the metal using MS toolchain and all the debug tools to see exactly what the code is doing. I was exploring what can be done using App Inventor thinking it could be something the cut and paste Arduino folks could use and I can hack up custom apps for others. Thanks for the link and the help.




Abraham Getzler

unread,
Jan 13, 2018, 9:40:45 PM1/13/18
to MIT App Inventor Forum
I notice you are using the Sound component instead of the Player, which can play longer files and has extra Events you can use to sequence sounds.

See attached for how you could replace all those individual Sound components with a single Player component and a list of pending sound files to play.

I started with two buttons, and quit when it got tedious.

ABG

midiplaytest_ABG.aia
blocks.png

Larry Deack

unread,
Jan 15, 2018, 10:04:59 PM1/15/18
to mitappinv...@googlegroups.com
Abraham,

Thank you for taking the time to look at this. The program I posted was a minimal size test case of my issue, not the real program. The real program uses a timer to fire off notes from a global queue much like you did. I have tried the player but repeating notes is too slow and I want short notes, very short notes not long files. I have a working program for what my friend wanted. He wanted to select 4 notes then make 24 buttons with all permutations so he can select them and add them to a list to be played. I have a global list of buttons so when they call me I can set and get stuff like changing the button to red as it plays.

 I also use a thumb slider value to change the timer as the notes play ( often long sequences of notes). I still get clicks for repeated notes or any note that gets played twice too fast because I actively stop the sound before I play it. Unfortunately there is some clicking oddness when stopping the .mid files that does not happen with the mp3 files. This can be replicated with the test file I uploaded by adding the stop before each play button. I let the user hit any button to immediately stop the playing and start the current group because when the tempo is slow you really do not want to wait so input of long strings of notes is easier. I also added the ability to edit the list. He want to be able to set the note value for each note and two octaves so I will add that and a staff view of the current note being played.

 It's been fun but I have other work to (pay bills) do so it may be a while before I have other questions. It's obvious that this whole area of using sound files this way is something not familiar to folks here. thanks anyway.

BTW, I was a C programmer so passing around structs of pointers is normal for me so lists of... whatever are an obvious way to go.
Reply all
Reply to author
Forward
0 new messages