MidiMon 1.00, a USB MIDI app
Lauren Etc. (8147) 52 posts |
I’m introducing MidiMon 1.00, an app designed to work with Rick Murray & Dave Higton’s USB-MIDI module. This provides a basic MIDI console monitor, as well as a virtual piano keyboard and the ability to send some common MIDI commands. Unfortunately, while I wanted to do more with it, in the end I had too much trouble getting my hardware and the module to work together consistently to get it all done, but I’ve cleaned up what I have and put together a release in hopes it might be of use to someone; it’s fully open source, so hopefully it can be scavenged for parts if nothing else. It has some helper modules that may be useful in some other applications. If anyone has a working USB MIDI setup on your RISC OS machine, drop me a line and let me know the hardware details, to say I am broke is an understatement but I’d love to revisit this some more later. Please be gentle though, this is my first RISC OS app! Wrapping this up and putting a bow on it will give me a chance to move on to some of the other RISC things I’ve been working on lately, mostly involving Python. Get it here: https://github.com/laurenrad/MidiMon |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
They were pretty much not supported until recently (now supported thanks to Ian). Try version 0.10: https://heyrick.eu/blog/files/usbmidi010.zip
Pi 2 (or 3B+), RISC OS 5.2x, my module, Yamaha PSR E-333. Plug’n’play in both directions. See also https://heyrick.eu/blog/index.php?diary=20230827#simpleseq |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lauren Etc. (8147) 52 posts |
Oh! I’m behind on versions once again, I’ll have to check it out 0.10! I need to keep up on your blog. I think it’s more than the module for me though, if I plug the presonus interface i have into my Pi half the time it freezes and a random app crashes, so there are deeper issues there… and the only other thing I have that might work is one of those generic cable ones. Budget and space limitations will probably prevent me from trying different hardware anytime soon but I’ll keep that in mind for the future. If you get a chance let me know if it does the basics with that Yamaha. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lauren Etc. (8147) 52 posts |
is it possible to delete a thread here? I’m not sure this is ready for primetime. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Dave Higton (1515) 3534 posts |
You can’t. I could, but I don’t see a good enough reason to do so. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
Connection stuff was changed quite a bit in recent versions. Shouldn’t have randomly crashed, more likely just fail to detect devices or endpoints. See if the new version is better. But note that the RISC OS USB stack is kind of fragile – I have a clever keyboard & touchpad combo that works as a keyboard but if I touch the pad, RISC OS immediately freezes.
I agree. The original post clearly discusses its limitations, so anybody using it does so with that understanding. Plus, if we waited for primetime, stuff wouldn’t ever get released. :P |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clive Semmens (2335) 3276 posts |
I have a keyboard and mouse shared between the Mac and the Pi, with a diode switch device to select which computer I’m using. They also share a monitor (well, a TV really), with two HDMI inputs I can switch between with the TV remote. Most of the time I can switch back and forth as much as I like, but occasionally when I switch back to the Pi, RISCOS has frozen. It’s not happened since I thought of being very careful not to knock the mouse as I switch, thinking that maybe some mouse communication switched in or out in mid message might be the problem, but I wasn’t aware of having knocked the mouse anyway, it wasn’t very frequent before, and it might just be luck. The Mac has never frozen at all at change-over (it has at other times, but that’s a different, known problem). |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Steffen Huber (91) 1953 posts |
It is also notable that, in my experience, some of these freezes are not real “hanging” crashes but something like busy-waits that never end – until you remove the USB device in question, and RISC OS suddenly starts to work again. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clive Semmens (2335) 3276 posts |
Switching the keyboard and mouse away from the Pi to the Mac, then back to the Pi, didn’t unfreeze the Pi, sadly. Tried that. I don’t have a Break key on the Mac keyboard that I’m using, so I don’t know if even Ctrl-Break would work or not, but possibly not since neither the keyboard nor the mouse seem to do anything at all when the Pi’s frozen. Tried using a keyboard with a Break key for a while, but it didn’t happen while I’d got that keyboard hooked up, and it’s not very good with the Mac so don’t want to keep it on long term. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Paul Sprangers (346) 525 posts |
I see this too, occasionally. But similar to what Steffen said, it can easily be solved by disconnecting the USB connector and connect it back again. Or is it really RISC OS that is frozen, and not just the keyboard/mouse? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Clive Semmens (2335) 3276 posts |
I didn’t think to try unplugging anything, thinking that switching the diode switch away from the Pi would be effectively the same thing. If it happens again, I’ll try unplugging things and plugging them back in. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Alan Adams (2486) 1149 posts |
This sounds like a problem I had on my ARMX6. I was (and still am) using a VGA 4-port KVM, and switching would randomly freeze the aRMX6, and more repeayedly freeze it if I moved the mouse while it was settling. Adding a USB3 externally powered switch between the KVM and the ARMX6 cured it. This in spite of the power draw of the KVM being less than 50mA – well below the amount the USB ports on the ARMX6 should have been capable of. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
Well… This is going well.
Right…
Anyway – some problems, but on the whole I think it’s a very useful test utility to ensure that a MIDI device is correctly working with RISC OS. It’s much friendlier than that crappy test program I threw together. Let me know when you have an updated version to play with (preferably a prebuilt app!). PS: Is it wise/safe to call Wimp_SendMessage from a module (not a task) while in a Service Call handler? You’ll be in SVC/IRQ mode and RISC OS is probably “busy” so…? 1 Merde! Mierda! Scheiße! (and you can guess the English one) 2 Paska! Cachu! 3 Given that texture is an important part of my food (I’m happy eating plain pasta tossed in a little butter or oil provided there are multiple sorts of pasta to provide varied textures), plus different tastes have colours associated with them (and whether or not I like something depends upon the colour as well as the taste perception, well, for me the colour is part of the taste perception)… yeah, I think I have some sensory miswiring. Did I mention that I’m a really picky eater? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
A quick program I threw together to test pitch bending (make sure it isn’t my module screwing up!). SYS "MIDI_SetTxChannel", 1 SYS "MIDI_TxNoteOn", 60, 80 FOR l% = 1 TO 20 : WAIT : NEXT SYS "MIDI_TxPitchWheel", &3FFF FOR l% = 1 TO 20 : WAIT : NEXT SYS "MIDI_TxPitchWheel", 0 FOR l% = 1 TO 20 : WAIT : NEXT SYS "MIDI_TxPitchWheel", &2000 MUST reset the pitch wheel to &2000 at the end, or the bending will ‘stick’. Anyway, this has the same effect as pressing C, D, A#, C. [hmm, only two notes – is there a way in MIDI to slide a large range of notes, like you can with many string instruments?] |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
Sussed it. Here’s an extreme example… REM Channel 1 SYS "MIDI_SetTxChannel", 1 REM Yamaha XG - switch to Er hu SYS "MIDI_TxControlChange", 0, 0 SYS "MIDI_TxControlChange", 32, 115 SYS "MIDI_TxProgramChange", 111 REM For non XG, you could use this for a cello: REM SYS "MIDI_TxProgramChange", 43 REM Select RPN &0000 -> pitch wheel adjustment SYS "MIDI_TxControlChange", &64, &00 SYS "MIDI_TxControlChange", &65, &00 REM Select 24 semitones (or two whole octaves) SYS "MIDI_TxControlChange", &06, &18 SYS "MIDI_TxControlChange", &26, &00 REM End RPN adjustment SYS "MIDI_TxControlChange", &64, &7F SYS "MIDI_TxControlChange", &65, &7F REM Slide from C4 to C6! SYS "MIDI_TxNoteOn", 60, 80 FOR l% = &2000 TO &3FFF STEP 64 SYS "MIDI_TxPitchWheel", l% WAIT NEXT REM Slide from C6 down to C2 FOR l% = &3FFF TO &1 STEP -128 SYS "MIDI_TxPitchWheel", l% WAIT NEXT REM And now back up to C4 FOR l% = 0 TO &2000 STEP 64 SYS "MIDI_TxPitchWheel", l% WAIT NEXT REM End this note now SYS "MIDI_TxNoteOn", 60, 0 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Dave Higton (1515) 3534 posts |
I had to look it up, but it does seem to be generally accepted that middle C is referred to as C4. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
Yes, the notes are tagged with an octave number (according to a full size 88 key piano) in “Scientific Notation”. The only time you should see negative octaves is if you have a piano with more than 88 keys (rare, but they do exist). |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lauren Etc. (8147) 52 posts |
To start with, thank you for taking a look Rick, I have to admit I wasn’t expecting much interest or attention which is why I threw it out as-is when I got a bit frustrated with trying to work around the hardware issues and wanted to move on without abandoning it. I’ll try to examine all this, but to answer a couple things real quick: - There is a binary build on the releases section of the Github repository, but I may want to see if I can make that a bit more visible. Especially since I left the debug flag in the Makefile in my haste.
It shouldn’t be there. I meant to have it hidden if debug was off or just remove it from the resource file, but again, I did it in a rush. I’ll make sure to deal with that.
I was attempting to mimic the behavior of some of the hardware I have, which has the octave as an offset from the middle octave which isn’t rigidly defined but C4 is a common option for middle C as Dave mentioned. I may see if I can make it more clear in the future, but I’ll have to think more about this one.
Indeed not likely to be useful but I just threw it in because it didn’t cost any extra to add.
I think I intended to add this to the Panic function but didn’t quite get to it.
Correct, the parsing right now is very stupid and only designed to handle fixed-size commands. I wanted to fix this but I couldn’t get the hardware working long enough to test things (the condition deteriorated over the course of development where when I started it usually worked and when I ended it didn’t at all), so I left it where it was where it could at least handle everything else.
In order to get key up events working (and this was needed to have the thing at all), I did something a bit nonstandard, so while it should honor the caret if hotkeys are disabled, otherwise this is the intended behavior for now. But I am curious if there is a better way to get key up events.
As has been pointed out to me, absolutely not. I’m not very bright. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
You’re welcome.
It has the potential to be a useful test tool.
Oh? I didn’t spot that.
Ah, it doesn’t crash. It adds a dummy entry to the scroll list, and then calls exit(). ;)
No, some parts of music aren’t rigidly defined, thanks to hundreds and hundreds of years of evolution. For completeness, I think this pretty much covers it:
(Textile completely lost its marbles over this table, so I had to rewrite it as an actual HTML table… :/ ) As you can see, the Helmholtz and English rapidly devolve into nonsense with all of that punctuation. I mean, “ To be fair – the reason Helmholtz/old English/old French (etc) use similar methods as Helmholtz designed this system in the middle of the 19th century, basing it upon Baroque organ tablature, which itself came from the Renaissance… Technically there are more – MIDI note 0 would be C-1, 108 would be C8, and 120 would be C9 but these are far out of the range of normal pianos. Hell, even my electric piano has so much interference in the playback that That being said, C0 is 16.something Hz, and the notation begins there as the average person isn’t actually able to distinguish frequencies less than ~20Hz as individual pitches. So while C-1 technically exists, it’s usefulness (and the ability of hardware to actually reproduce it) is rather limited.
I think the appallingly naff keyboard handling has been visited numerous times in the history of RISC OS. There’s nemo’s DeepKeys module, Ovation(Pro) ships with a helper module that’s aimed at working out which keys were actually pressed. I’m sure somebody somewhere has wanted to know when a key was released without continually polling for it. So.. yeah…
RISC OS is a bit fragile in places. ;)
The way I’d handle this is to pop the key press/release into a buffer (make the buffer suitably large that you can handle multiple key actions). If you terminate the buffer with a null word, you can then simply give the buffer address to the Wimp to treat as a poll word. If nothing happened, the first word will be the null terminator so the Wimp won’t do anything. I notice your NoteOff comment says that for reasons you don’t recall, you actually use NoteOn with a velocity of zero. There’s actually a reason for this – and why the MIDI spec supports both methods – in the old days of serial MIDI there was a thing called “running status” where you’d send a “Note On” command, followed by a note, and another, and more notes. Because MIDI commands have the high bit set, and parameters don’t, it is easy to tell that “Note On” followed by eight bytes with bit 7 clear would actually be four individual Note On requests. For the first, the Note On was specified, but for the remainder, it was assumed. Thus effectively saving the time necessary to send one byte for every note. It adds up. Obviously this falls apart a little when one interface is talking to multiple channels, so these always need to be specified; but even so – depending upon the music – running status could save time. So Note On 0 is equal to a Note Off.
I think you mentioned having a cheap MIDI interface? If it’s a QinHeng CH345, be aware that there are some notable bugs:
There’s a reason why the flag in my device array (in the MIDI module source) is called “craphardware”. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Colin Ferris (399) 1818 posts |
Interesting – up and down output of the keyboard ‘down’ key so you could time the length of Morse code Dit’s/Dar’s. Also a way of getting Morse output from a Morse key connected to serial port or a USB/serial port? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Lauren Etc. (8147) 52 posts |
Hey you and me both, Textile has been driving me up the wall. So not saying you’re wrong about the octave thing, but thinking back through my process, I remember why I did it this way: this is exactly how my old Midiman Oxygen 8 behaves; it’s a two octave controller and it starts with the lowest key’s octave on a “center” value it calls “0”, and there are two buttons to shift down to -4, or up to +4. So, that’s my excuse. I also believe this is a fairly common way for smaller controllers to operate, and that was the intended skeuomorphism behind it (that and the Casio VL-Tone VL-1 inspiration to make the simple button keys look as decent as I could). It should be able to make all valid MIDI notes at any rate I believe, which is the main intention since it’s not going to be useful for performance; it’s to let you send test messages encompassing as much of the MIDI spec as possible, whether they’re useful or not.
I went back to this comment and to clarify, it can actually do note off both ways with a choice, but what the comment was referring to is that I had some trouble or confusion or something with the MIDI_TXNoteOff SWI and ended up constructing the note off myself with MIDI_TxCommand. Might look at it later, but… … You’re right about the KeyUp thing, but I went back to it last night and realized I don’t have the Wimp maneuvering down enough to know how to solve it. So I’m putting this one on the shelf for just a few while I do another project that will help me learn what I need to put out a fix, unless someone wants to contribute one. Oh also:
I have one of those AND a presonus one that are both wonky for different reasons, but anecdotally, when I broke out the new version of USB-MIDI the other day it seemed to behave, so it’s worth another look. But yeah, I’m aware of the limitations with that one. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Steve Pampling (1551) 8172 posts |
Not withstanding the habit of the forum setup overall making a dog’s breakfast of the user input, it might be helpful if the "See also the Textile reference here actually pointed to a live link of helpful info – like https://textile-lang.com/
Yeah, best not to argue with the conventions of the professional musicians (western world set) when they’ve been using those conventions for many generations. Edited round the link because textile… |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Peter Everett (9846) 59 posts |
I tweeked my MIDI Support system to provide !MidiMon with the responses it Midi Support might help with testing as you can create loop backs without As Midi Support and Ricks USB Midi both use the same Acorn Midi SWI’s |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Rick Murray (539) 13850 posts |
How is it not working?
Yup, that’s a good idea.
That’s probably just as well. Multiple things trying to control the same hardware doesn’t tend to end up in a good place.
In my experience, the main problems aren’t so much the drivers, it’s getting the hardware doing what is expected. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
Peter Everett (9846) 59 posts |
although I haven’t quite figured out what’s up with the pitch wheel. It gives a repeating fixed number LSB 40 MSB 7D when the mouse is clicked anywhere on the bar or dragged along it and a single 10-49 when the mouse is released. I’m investigating further because it might be, how shall I put it, a small negative enhancement in my code :-)
Too many unknowns when you’re trying to sort out your own code. That’s the nice thing about using a UART instead of USB. You can loop back tx to rx directly on the Pi expansion header without any additional hardware. The pins are next to one another as well. |