SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => Topic started by: wadmixfm on July 21, 2019, 22:08:55

Title: RTMIDI........
Post by: wadmixfm on July 21, 2019, 22:08:55
hello again

i am currently updating my old version of Specdrum which is a drum machine sequencer which was written by 2 guys called A.pateman & P Hennig of cheetahsoft days 1985

just recently they have released a newer version of Specdrum for Android devices etc.....

so i thought i would update my version of the 1985 original with a few extras , like mixer , tuning , midi , auto play , sorry i will get on with the question now :)

i am or have added RtMidi to the program and it works great but i am having one little issue

is there a way to change the midi out channel with RtMidi ??

when i use the code which is wrapped by brucey henderson it only plays on channel 1

most synths or drum machines have a dedicated channel 10 midi in

is this possible ???

sorry to be long winded there :)

here are some pics of my sequencer running :)



Lee B
Title: Re: RTMIDI........
Post by: Brucey on July 22, 2019, 06:22:05
Hello, apparently the channel is encoded into midi message.

There's a bit about it here : https://github.com/SpotlightKid/python-rtmidi/issues/38#issuecomment-448655644
Title: Re: RTMIDI........
Post by: Yellownakji on July 23, 2019, 03:12:37
I'm surprised RTMIDI works to begin with...

Never got it to function in my life.
Title: Re: RTMIDI........
Post by: iWasAdam on July 23, 2019, 07:47:41
Yep, As Brucey says: You will need to decode the Midi messages. Both for sending and receiving.

RTMidi just gives you access to the data stream. Everything else you need to code.

One thing I noticed is that when first activating Midi (scanning) there will be a pause before program control is returned. So it might be a good idea for you to give users the option to activate when they want and not when the app starts - thus preventing a pause!

Midi data itself isn't complicated. but you will need to do some bit level stuff on bytes and nibbles...
Title: Re: RTMIDI........
Post by: wadmixfm on July 27, 2019, 21:48:55
Thanks for the info and replies

i used portmidi before and that was in the message data too i will have a look at the info cheers Brucey

i have created a midi menu page at the top of my program now so the user can select the midi device in the list and then in the program you can turn the midi out on and off

cheers

i have got it really close to the original :)

1 more little question

which is the best audio driver to use for audio output with regards to latency ??? OpenAl or just direct sound nowadays

at the moment i am using Freeaudio and it seems to be ok

Lee
Title: Re: RTMIDI........
Post by: Yellownakji on July 27, 2019, 22:48:39
Personally, i always use DirectSound for Windows and FreeAudio for Macintosh and Linux.  For Windows, FMOD is also really good but will require to have an ugly DLL in your project folder, so i never touch it. 
Title: Re: RTMIDI........
Post by: wadmixfm on July 28, 2019, 00:37:52
I have worked out a few of the RTMidi control and program changes hope this helps


' Simple program to test MIDI output.

SuperStrict
Framework BaH.RtMidi
Import BRL.StandardIO

Local midiOut:TRtMidiOut = New TRtMidiOut.Create()

If midiOut.getPortCount() = 0 Then
   Print "No Output Ports"
   End
End If

For Local i:Int = 0 Until midiOut.getPortCount()
   Print "  Output port #" + i + " : " + midiOut.getPortName(i)
Next

Print "Opening " + midiOut.getPortName()

midiOut.openPort(2) ' this is my midi device , you will have to check for your own :)


Local message:Byte[] = New Byte[3]

' Send out a series of MIDI messages.

' Program change ( Midi channel , value)
' 192 = ch 1 , 5 =  Elec Piano 2
' 193 = ch 2
' 194 = ch 3
' 195 = ch 4
' 196 = ch 5
' 197 = ch 6
' 198 = ch 7
' 199 = ch 8
' 200 = ch 9
' 201 = ch 10 *Note* Gm drumkits patch numbers are 0 = standard , 8 = room set , 16 = power set , 24 electric set , 25 Tr808 set ,32 = jazz set , 40 = Brush set ,48 = Orch set
' 202 = ch 11
' 203 = ch 12
' 204 = ch 13
' 205 = ch 14
' 206 = ch 15
' 207 = ch 16


message[0] = 201 ' this is channel 10 , i used this on my drum module
message[1] = 0 ' this is my standard kit
midiout.putMessage(message, 2)

message = New Byte[3]
' control change ( Midi channel , control , value)
' 176 = ch 1 , 7 = Vol , 100 (0-127)
' 177 = ch 2 , 10 = Pan , 64 (0 - 64 - 127) 0 left / 64 center / 127 right
' 178 = ch 3
' 179 = ch 4
' 180 = ch 5
' 181 = ch 6
' 182 = ch 7
' 183 = ch 8
' 184 = ch 9
' 185 = ch 10
' 186 = ch 11
' 187 = ch 12
' 188 = ch 13
' 189 = ch 14
' 190 = ch 15
' 191 = ch 16

message[0] = 185 ' this is channel 10
message[1] = 7 ' control change 7 for volume there are others 10= pan 91=reverb 93=chorus
message[2] = 120 ' volume is now set to 120
midiout.putMessage(message, 3)

message = New Byte[3]

' Note On: 144, 64, 90
' Note on  ( Midi channel , note , velocity)
' 144 = ch 1 , 36 = C 2 , 100 (0-127)
' 145 = ch 2
' 146 = ch 3
' 147 = ch 4
' 148 = ch 5
' 149 = ch 6
' 150 = ch 7
' 151 = ch 8
' 152 = ch 9
' 153 = ch 10
' 154 = ch 11
' 155 = ch 12
' 156 = ch 13
' 157 = ch 14
' 158 = ch 15
' 159 = ch 16

message[0] = 153 ' this is channel 10
message[1] = 36 ' C 2 on a keyboard or Kick drum on a drum module
message[2] = 100 ' velocity set to 100
midiout.putMessage(message, 3)

Delay(500)

message = New Byte[3]

' Note Off: 128, 64, 40
'note off 128 = clear note data , Note 36 = C2 ,Velocity 40
'as long as the note you used in note on make sure the note is used after the code 128 to clear that note

message[0] = 128
message[1] = 36
message[2] = 40
midiout.putMessage(message, 3)

message = New Byte[6]
' Sysex: 240, 67, 4, 3, 2, 247
message[0] = 240
message[1] = 67
message[2] = 4
message[3] = 3
message[4] = 2
message[5] = 247
midiout.putMessage(message, 6)

midiout.free() ' lets close the midi port


Lee
Title: Re: RTMIDI........
Post by: Hezkore on July 28, 2019, 01:02:27
This may be totally unrelated to this thread, and if so I'm sorry.
But I'm curious...
How hard would it be to read Midi files and then manually play them via something like the 'Microsoft GS Wavetable Synth'?
I'd also like to read the Midi data my keyboard/synth outputs and make some sort of music game out of it.
Title: Re: RTMIDI........
Post by: wadmixfm on July 28, 2019, 01:37:29
well it can be done but in my instance i am just using midi out from a drum based sequencer i am reviving :)

so all i am using the midi for is a trigger to send to a drum module to play the sounds and in the program i am writing i can use the samples in the program as well

RTmidi ..... seeems quite well documented and i dont know how far you want to go with it but for me its pretty damn good.

my sequencer just uses note on note off velocity volume pan and effect send to reverb and chorus and as you can see from the example i have posted i have documented the out status

the only thing about rtmidi and i think with portmidi too you have 3 bytes (message 0 ) is the channel , (message 1) is the note or control , (message 2) is the value

thats all i have used

have fun and i hope it helps

lee

Title: Re: RTMIDI........
Post by: wadmixfm on July 28, 2019, 01:39:31
and i think someone posted not long ago about midi files , you could use fmod as that has a midi file reader in its code

maybe look at that :)

Lee
Title: Re: RTMIDI........
Post by: wadmixfm on July 28, 2019, 01:43:49
try here

https://www.syntaxbomb.com/index.php/topic,5038.msg21146.html#msg21146


or here

http://mojolabs.nz/posts.php?topic=41983
Title: Re: RTMIDI........
Post by: wadmixfm on July 28, 2019, 20:03:06
here are some little screenshots from my attempt at an old conversion of specdrum from 1985 , i have contacted A.pateman and P.Hennig the original coders of specdrum and they want me to send them a complete version of this :)

Good old Cheetahsoft :)

Lee  :P
Title: Re: RTMIDI........
Post by: fielder on July 29, 2019, 08:33:09
and also: https://www.blitzforum.de/forum/viewtopic.php?t=36697
Title: Re: RTMIDI........
Post by: Hezkore on July 30, 2019, 03:30:08
I'm having quite the delay using the Microsoft GS Wavetable Synthesizer.
Anyone know of a workaround?

Been looking at this, but I'm confused: https://github.com/KeppySoftware/OmniMIDI/blob/master/DeveloperContent/KDMAPI.md (https://github.com/KeppySoftware/OmniMIDI/blob/master/DeveloperContent/KDMAPI.md)
And it seems like people use the old bassmidi.dll to basically emulate the MS GS wavetable synth, just with a lot less delay.

I'd like to avoid having people install third party apps and sound fonts, just to get rid of the delay.
Title: Re: RTMIDI........
Post by: iWasAdam on July 30, 2019, 05:33:10
what sort of delay?
initial connection to RTMidi when first scanning may have a delay of a few seconds or more. but once connected everything is 1:!
Title: Re: RTMIDI........
Post by: Hezkore on July 30, 2019, 15:25:58
No the initial connect time is very fast.
But after pressing a key; hearing the sound is delayed.
It takes several hundred milliseconds before you actually hear the sound.
And it's apparently a known issue with the Microsoft GS Wavetable Synthesizer.
A quick Google search reveals it's been a problem the MS GS wavetable synth has had for years now. :(
Title: Re: RTMIDI........
Post by: Hezkore on August 01, 2019, 23:46:10
I'm still battling the delayed audio.
But I have at least made some progress in other parts.
I can read and send Midi easily now.
I can play notes on my keyboard and send the data to a Midi synth on the computer.
And I can send Midi from the computer into my keyboard and have it be the synth.
And I've started processing Midi files as well:
Title: Re: RTMIDI........
Post by: wadmixfm on August 04, 2019, 15:35:11
have you tried an external midi device and is that delayed ???
Title: Re: RTMIDI........
Post by: wadmixfm on August 04, 2019, 15:41:04
or even a standalone vst and use something like midiyoke to create a virtual port see if that delays , it could just be the way windows ports the audio

i know this might sound long winded try it on another machine like with windows xp or windows 7 because i have tried windows xp before with midi and that was very responsive )

its just to eliminate the cause and yes i know before anyone else says it xp did not use wdm drivers for the audio as they were native but windows 7 did and i got the same results :)

Lee
Title: Re: RTMIDI........
Post by: Hezkore on August 04, 2019, 16:05:13
RTMIDI is not delayed.
It's the Windows GS Wavetable synthesizer.
So sending midi works fine, receiving midi works fine.
It's when you send midi data to the MS GS wavetable synth that the audio it produces is delayed.
So using any other output, like OmniMIDI, VirtualMIDISynth or even your external Midi device (like a keyboard) will not be delayed.

The problem for me is that this is an application that runs on the computer, and I want the sound to come out of the computer.
And 99% of the users would not have any other midi synth than what comes with Windows.
So they'd all experience audio delay.
Title: Re: RTMIDI........
Post by: wadmixfm on August 04, 2019, 17:35:15
https://www.pgmusic.com/tutorial_bbwlatency.htm


hope this helps

lee

Title: Re: RTMIDI........
Post by: Hezkore on August 04, 2019, 17:42:46
There's no other way than using a third party synthesizer, software or hardware.
The Windows GS Wavetable synthesizer is very old and outdated.
The only solution I have is to use a third party library that instead can interpret the Midi signals.

This seems like a good Open Source library (and app): https://github.com/KeppySoftware/OmniMIDI
It's got its own API you can use, so that you don't need the app: https://github.com/KeppySoftware/OmniMIDI/blob/master/DeveloperContent/KDMAPI.md
But I haven't looked into it much further than that, not tried implementing it.

There's also the old bassmidi.dll, which I've seen some people use in the past.
But not looked into that either.
Title: Re: RTMIDI........
Post by: wadmixfm on August 04, 2019, 17:47:46
what about asio4all

then you can lower the latency of the audio

to around 3ms which is about 256k buffer

its very tricky :)