JavaScript, Python, Java, C# API for manipulating, and writing MIDI [Modified]

Started by chikitin, January 23, 2019, 12:53:24 AM

Previous topic - Next topic

chikitin

Hi,

Can anyone here referent me to a solid JavaScript, Python, Java, C# API for reading, manipulating, and writing MIDI files type 0. I'd like to write my own utility program using it.

Any help would be greatly appreciated.

CS

Jørgen

Hi

MIDI classes have been part of the Java Development Kit - JDK - for ages...

Thousands of web sites with code examples...

A short primer at http://www.jososoft.dk/yamaha/pdf/MIDI_in_Java.pdf

Jørgen
The Unofficial YAMAHA Keyboard Resource Site at http://www.jososoft.dk/yamaha
- since 1999

pfeuh

Hello,

For python I use pygame because there are drivers both for midi in and midi out. But it's really far of the best drivers of the world. Another problem is that you have to know a lot about deploying a python application, pygame is not so easy to embark in an application.

Regards,

Pfeuh

chikitin

Thank you very much Jørgen for the great resource and Pfeuh for the suggestion.
I just changed the title after doing some more research!

It seems c# and java are contenders for my job. Both are now cross platform. I have never programmed in C# however, I think it is fairly easy as I am pretty good at Java.

Jørgen

Hi

Java and C# syntax is pretty much the same.

Java has had MIDI support for ages.

C# has just recently - Windows 10 - got MIDI support:  https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/midi
I have used third party libraries in C# http://www.jososoft.dk/yamaha/articles/software_4.htm

Jørgen
The Unofficial YAMAHA Keyboard Resource Site at http://www.jososoft.dk/yamaha
- since 1999

BenoitM

For .Net , give NAudio a try, it's free and open source:  https://github.com/naudio/NAudio

It's a general audio library, using Windows components to read/write/encode/decode MP3, WAV, AIFF files and it can read/write MIDI files, and Send/Receive MIDI events...

chikitin


Tyros5Mad

@chikitin: Naudio is mainly for audio. It does have routines for handling midi but no methods for playing midi files unfortunately.

@Jorgen:  I am definitely interested in the windows 10 midi support. I will look into this.

Richard

chikitin

Quote from: RichardL on January 23, 2019, 07:45:09 PM
@chikitin: Naudio is mainly for audio. It does have routines for handling midi but no methods for playing midi files unfortunately.



Richard, I don't care for midi playback! It seems I can MIDI file manipulation very well.

Thank you.

BenoitM

One word of Advice about C# / .Net beeing cross-platform now : yes, .Net Core runs on Windows, Linux, Mac, but there's no client-side U.I. stack (yet) on .Net Core ... If you need a client cross-platform U.I. now on .Net you have to use Mono or Xamarin, both having their own shortcomings... (if the U.I. is simple, Mono or Xamarin can handle it, other libraries like 'Avalonia' exists, but are not ready for real-world projects ...). If you want to develop a cross-platform Web App, .Net Core is currently the best 'in-the-box' offer in the .Net Universe...

.Net Core 3.0 - to be release first or second quarter of 2019 - will contains a WinForm and WPF package, but only for Windows (yes, strange but true... MS seems to have lost interest in client-side app development tools in favor of Web Stack ... They see HTML/Javascript as the holy grail of cross-platform dev - using transpiller like TypeScript, and MVC framework to isolate the developer from html hand-coding - but the truth is that some apps are better as client-side apps ... but I disgress  ::)  )

If you have more experience with Java, use Java ! Yes, at first glance C# and Java have similar syntax, but when you dive into both platforms, there's more differences than you can think (take the 'Generics' : at first glance they have similar syntax and usefulness in both platform, but under the hood they are implemented really differently...). Having used both platform, they have their own strength and weakness... for your project, Java has more 'builtin' classes to handle the Cross-platform U.I. and Midi file handling, but it is still doable with .Net if you use third-party libraries and Mono or Xamarin...

Personaly, when I don't need cross-platform client-side U.I. I tend to choose .Net (I prefer the C# syntax and features link LINQ, Tuples, Async, Generics, Extension Methods, and so on...) , I only use Java when I need a cross-platform client-side U.I. (but it is still a lot of work to have a nice GUI , that's why a lot of Java developers are still using the old 'battleship grey' U.I. stack  ;D

Benoit

Jørgen

Right, Benoit

.Net - C# - is behind in MIDI implementation
Java is behind in UI design

Jørgen
The Unofficial YAMAHA Keyboard Resource Site at http://www.jososoft.dk/yamaha
- since 1999

chikitin


pjd


Here's a small Java MIDI application that I built some time ago.

http://sandsoftwaresound.net/java-note-mapper-v0-1/

The code should give you some idea about the Java MIDI API and how to use it.

Have fun!

-- pj

Tyros5Mad

I used the MidiSharp library for writing my MidiMaker program and it worked well for me.

On the technical side:
The problem I have working with our Yamaha synths is the fact that Yamaha uses the XF format for their step record mode.

So in Midi Maker I create a file with sy*** chords and I can play that direct via USB midi to the keyboard, no problem.

However, when I take that file over to the keyboard and try to play it in step record mode it does not work because there is no XF chord data.

Peter Weirsba, the programmer for Producer, has the opposite problem. He creates an XF format midi file for Step Record but that will not play to the keyboard via midi. So to play the file while making it in Producer, he has to make a separate file with sy*** chords like I do.

I want to create a an XF file but I do not know how to do that. The docs I have read are not very helpful, or maybe I am just not savvy enough to fully understand them.

So, if anybody can help me with easily understandable info for writing an XF file, I would be very grateful.

Regards, Rich

chikitin

Quote from: RichardL on January 24, 2019, 06:14:34 PM
I used the MidiSharp library for writing my MidiMaker program and it worked well for me.

So, if anybody can help me with easily understandable info for writing an XF file, I would be very grateful.

Regards, Rich

I had the old XF format document published by Yamaha. Unfortunately, I cannot find it anymore it was on my MBP that got toasted.

I guess we need to hire hackers to decipher the Yamaha formats (kidding!)
May I am sounding vague, but I don't think it is hard to reverse engineer the formats ( encryption algorithm) as we have the Machine ( Synth) and we can do Chosen-ciphertext attack on XF formats and any other formats used.

Tyros5Mad

Not that easy to reverse engineer the XF file. I have tried numerous programs but none of them can read the XF data part of the midi file.

PSRUTI, MixMaster etc, all programs written for Yamaha keyboards just ignore the XF chunk in the midi file.

Rich

SeaGtGruff

Quote from: chikitin on January 24, 2019, 07:57:30 PMI had the old XF format document published by Yamaha. Unfortunately, I cannot find it anymore it was on my MBP that got toasted.

I have it on a USB flash drive. I'll look for it later, although I imagine that Jorgen either has it on his site, or has a link to it.

Tyros5Mad

I have all the XF docs that I could find on the internet. They explain what needs to go into an XF file but not how to write it.

I get around the problem quite easily though by using XGWorks  or Producer to write the XF file. I am just peeved that I cannot write the file in my software myself.

Rich

SeaGtGruff

I thought an XF file is simply a MIDI file, except that it also contains XF messages?

Jørgen

The Unofficial YAMAHA Keyboard Resource Site at http://www.jososoft.dk/yamaha
- since 1999

Jørgen

The Unofficial YAMAHA Keyboard Resource Site at http://www.jososoft.dk/yamaha
- since 1999

Tyros5Mad

Quote from: Jørgen on January 25, 2019, 01:23:18 AM
It is!

Jørgen

It is guys but the problem is it must be done in a way such that the keyboard can read it AND be able to expand it into a full midi file. I will show an example of what I mean in a new post. I just need to prepare the info first.

Rich

Tyros5Mad

Example 1

Here's a dump of a proper XF file that can be read by the keyboard AND be expanded. Note you cannot see any chord info, Tempo, or style control info but the keyboard can read the this info.

If you open this file in a program like PSRUTi or Mixmaster you get a message "Some more data behind SMF tracks are ignored"

Rich

[attachment deleted by admin]

Tyros5Mad

Example 2

Here's a dump of a style control file (normal midi file) with all the "missing" info. The keyboard can read this info and play it but not expand it into a normal midi file.

So that's the problem. I need to be able to write a file with the hidden data. This data is hidden in a separate chunk, which is not a normal MtHd header chunk.

Rich

[attachment deleted by admin]

Jørgen

The Unofficial YAMAHA Keyboard Resource Site at http://www.jososoft.dk/yamaha
- since 1999

Tyros5Mad

I do not need to extract the lyrics. I already have the lyrics.

However, all this discussion has given me some ideas to follow.

Regards, Rich

chikitin

Thank Everyone again.

I decided to use javax.sound.midi package for all the good reasons above!

I understand track is a way to get around the limitation of having 16 channels of MIDI data in Midi files. How can I extract all the MIDI data in a give track? I assume the method signature:

public Sequence split(Sequence in, int channelNo, Track tr)  throws IOException

Let's assume MIDI file type is 0.




Tyros5Mad

I've got this now. I used a hex viewer to look at a step record file and I can see the added data at the bottom of the file. Now to figure out how to write this data.

Thanks all for the comments.

Rich

[attachment deleted by admin]