microsoft / pxt-midi

A MIDI interface for MakeCode
https://makecode.microbit.org/pkg/microsoft/pxt-midi
MIT License
32 stars 21 forks source link

Midi signal via serial seems wrong #4

Closed JonahPi closed 6 years ago

JonahPi commented 6 years ago

I used the Midi package with a very simple program but was not able to get out any tone. Using a similar Python code worked perfectly fine. In both cases I transmit the Midi-code via Pin 0 and use the Midi via Serial command. When I compared the signals from the Phython code with the one from the PXT-code there was an obivious difference. (s.a. forum entry here: link )

Gadgetoid commented 6 years ago

I've just realised this when testing today- it's not actually sending MIDI over Serial at all, but is instead sending a string representation of it.

See: https://github.com/Microsoft/pxt-midi/blob/fb9de98860c6c5cd0a60844673f450f1bc55abbf/midi.ts#L80-L95

The practical upshot of this is that the "MIDI" is very human-readable, but unfortunately isn't readable by any off-the-shell Serial->MIDI bridge software I've come across.

The format is:

midi:<command>,<arg>,<arg> \r\n

(Not I've taken liberty with the amount of whitespace, but that is part of the output)

You could write your own client in Python that handles MIDI messages in this format and injects them directly into the system. It'd be relatively easy using serial.readline.

However I think this library needs a new block: "useRawSerial()"

This block would run the following code:

function send(data: Buffer): void {
    serial.writeBuffer(data)
}
midi.setTransport(send);

This writes the raw - not human readable - MIDI data directly out to the serial port, and I can confirm this works with Hairless MIDI <-> Serial Bridge.

JonahPi commented 6 years ago

Using the new block "midi use raw serial" it works like a charm. Thanks a lot for your help!

pelikhan commented 6 years ago

Anyone up to write a project on how to use this?

JonahPi commented 6 years ago

micromidiconnection microbitsamplecode

This setup allows to connect any kind of instrument with a midi-input. I tested it with an e-piano and this little devices which was described in the German Make magazine.

CaptainCredible commented 6 years ago

Nicely done! I originally wrote my own package for this that I haven't put on gitgub yet. I have however run into trouble with hardware serial bytes inexplicably going missing both on tx and rx. Have you stress tested this yet?

On Sun, 20 May 2018, 23:27 JonahPi, notifications@github.com wrote:

[image: micromidiconnection] https://user-images.githubusercontent.com/6844732/40283811-cb598e68-5c84-11e8-83fb-8eac127f9430.PNG [image: microbitsamplecode] https://user-images.githubusercontent.com/6844732/40283815-d0789f92-5c84-11e8-83f7-3a36d9d7d573.PNG

This setup allows to connect any kind of instrument with a midi-input. I tested it with an e-piano and this little devices https://www.heise.de/make/meldung/NanoSynth-Breakout-Board-fuer-mehrstimmigen-Musikgenuss-3982004.htmlwhich was described in the German Make magazine.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/pxt-midi/issues/4#issuecomment-390514128, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQ0FUHn8N7pEq_Ciwv-sxm-HfqcuwgFks5t0d_RgaJpZM4S51TI .

pelikhan commented 6 years ago

@JonahPi , could we add this to the readme?


From: CaptainCredible notifications@github.com Sent: Sunday, May 20, 2018 2:38 PM Subject: [Microsoft/pxt-midi] Midi signal via serial seems wrong (#4) To: Microsoft/pxt-midi pxt-midi@noreply.github.com Cc: Peli de Halleux jhalleux@microsoft.com, Comment comment@noreply.github.com

Nicely done! I originally wrote my own package for this that I haven't put on gitgub yet. I have however run into trouble with hardware serial bytes inexplicably going missing both on tx and rx. Have you stress tested this yet?

On Sun, 20 May 2018, 23:27 JonahPi, notifications@github.com wrote:

[image: micromidiconnection] https://user-images.githubusercontent.com/6844732/40283811-cb598e68-5c84-11e8-83fb-8eac127f9430.PNG [image: microbitsamplecode] https://user-images.githubusercontent.com/6844732/40283815-d0789f92-5c84-11e8-83f7-3a36d9d7d573.PNG

This setup allows to connect any kind of instrument with a midi-input. I tested it with an e-piano and this little devices https://www.heise.de/make/meldung/NanoSynth-Breakout-Board-fuer-mehrstimmigen-Musikgenuss-3982004.htmlwhich was described in the German Make magazine.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/pxt-midi/issues/4#issuecomment-390514128, or mute the thread https://github.com/notifications/unsubscribe-auth/AMQ0FUHn8N7pEq_Ciwv-sxm-HfqcuwgFks5t0d_RgaJpZM4S51TI .

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2Fpxt-midi%2Fissues%2F4%23issuecomment-390514886&data=02%7C01%7Cjhalleux%40microsoft.com%7C9e5466dbaf65435f76dc08d5be9a008f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636624491008805452&sdata=3sTPDlL%2BOX4%2BVXpljS5Hz0z4T6UkNfdArVdh%2FcFUKAA%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAD-4Kb4avd475KLIeboXM0sXojzAsW6eks5t0eJKgaJpZM4S51TI&data=02%7C01%7Cjhalleux%40microsoft.com%7C9e5466dbaf65435f76dc08d5be9a008f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636624491008805452&sdata=GUHalN1%2B1%2Bvss1%2FbX77pqW3Vwd1JJqP8MFV1XE04ya8%3D&reserved=0.

JonahPi commented 6 years ago

@pelikhan : Sure, 'would be cool to see more people using it.

@CaptainCredible : No long time tests run yet but I will work on a midi project soon, 'hope it works out.

pelikhan commented 6 years ago

@JonahPi can also help adding to the default list of projects.


From: JonahPi notifications@github.com Sent: Monday, May 21, 2018 1:14 AM Subject: [Microsoft/pxt-midi] Midi signal via serial seems wrong (#4) To: Microsoft/pxt-midi pxt-midi@noreply.github.com Cc: Peli de Halleux jhalleux@microsoft.com, Mention mention@noreply.github.com

@pelikhanhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fpelikhan&data=02%7C01%7Cjhalleux%40microsoft.com%7Cd254c2799f204539973e08d5bef2e24b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636624872747611375&sdata=WfhK3vtNUmjYWONpaZcCN1YvqR9GLrjwsM1BduTIqCI%3D&reserved=0 : Sure, 'would be cool to see more people using it.

@CaptainCrediblehttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FCaptainCredible&data=02%7C01%7Cjhalleux%40microsoft.com%7Cd254c2799f204539973e08d5bef2e24b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636624872747611375&sdata=DtXlE4Bf9RcIiI7ojAKSxn70mKGdiiaBN2ikrQ8CCiU%3D&reserved=0 : No long time tests run yet but I will work on a midi project soon, 'hope it works out.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2Fpxt-midi%2Fissues%2F4%23issuecomment-390585357&data=02%7C01%7Cjhalleux%40microsoft.com%7Cd254c2799f204539973e08d5bef2e24b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636624872747621379&sdata=uRNYQXz%2FIeIVCjXTDQqx85NV1QXWIKSJdIiummKhoKs%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAD-4KQSPi8jieDN4odVjyRvrnD82bDGUks5t0ndogaJpZM4S51TI&data=02%7C01%7Cjhalleux%40microsoft.com%7Cd254c2799f204539973e08d5bef2e24b%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636624872747631388&sdata=F06v%2BQffzx5Is4aMcsUTb3n89YrVB3XY4RRQYR0dMHc%3D&reserved=0.

JonahPi commented 6 years ago

In this case I think it should be a little bit extended to see the differences between polymorphic and single tones:

let Guitar: midi.MidiController = null
input.onButtonPressed(Button.A, () => {
    basic.showIcon(IconNames.EigthNote)
    Guitar.note(midi.frequencyToKey(262), music.beat(BeatFraction.Whole))
    basic.pause(100)
    Guitar.note(midi.frequencyToKey(330), music.beat(BeatFraction.Whole))
    basic.pause(200)
    Guitar.note(midi.frequencyToKey(440), music.beat(BeatFraction.Whole))
    basic.pause(300)
    basic.showIcon(IconNames.Yes)
})
input.onButtonPressed(Button.B, () => {
    basic.showIcon(IconNames.Heart)
    Guitar.noteOn(midi.frequencyToKey(262))
    Guitar.noteOn(midi.frequencyToKey(330))
    Guitar.noteOn(midi.frequencyToKey(440))
    basic.pause(800)
    Guitar.noteOff(midi.frequencyToKey(262))
    basic.pause(500)
    Guitar.noteOff(midi.frequencyToKey(330))
    basic.pause(500)
    Guitar.noteOff(midi.frequencyToKey(440))
    basic.showIcon(IconNames.Yes)
})
serial.redirect(
SerialPin.P0,
SerialPin.P1,
BaudRate.BaudRate31250
)
midi.useRawSerial()
basic.showIcon(IconNames.Yes)
Guitar = midi.channel(1)
Guitar.setInstrument(MidiInstrument.AcousticGuitarNylon)