Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[Free] Midi Player Tool Kit Available !

Discussion in 'Made With Unity' started by BachmannT, Apr 14, 2018.

  1. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hi
    The issue has been found. But I can't publish a new version now, I need to make serious test before and I'm going in holidays.
    In the meantime, you could correct directly in the SF generated.
    1. Open this folder Assets\MidiPlayer\Resources\SoundfontsDB\GeneralUser_GS_SoftSynth_v144, and edit file GeneralUser_GS_SoftSynth_v144.txt
    2. Search for <Patch>65</Patch>
    3. Into this patch, search for each <ImSample> and set <IsLoop>false</IsLoop> to <IsLoop>true</IsLoop>. You may find 13 ImSample for this patch.
    Thank a lot for your very well documented problem. It's pleasant and more efficient for me.
    I apologize for this issue, a corrected MPTK will be available soon.

    BR
    Thierry
     
    Last edited: Nov 8, 2018
  2. ProSourceLabs

    ProSourceLabs

    Joined:
    Dec 9, 2016
    Posts:
    93
    Hello. Would like to ask which platforms are supported with this plugin. Mobile / html5/pc/smart tvs are of importance. Does it use native plugins ? or is it all C# code.

    Thanks.
     
  3. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hello
    No native plugins.
    All the C# code is available with the package.
    Soundfont and Midi reader are based on NAudio.
    Synth component is based on Unity AudioSource.
    Tested only on desktop Windows. But some users use MPTK on Android.

    The good approach could be to check with the free version, if you have issue I could help you.

    BR
    Thierry
     
  4. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hello
    The version 1.95 is available with a correction on the Loop wave attributes which have affected some presets. Thank to rn9dfj3 for the detailed case published!
    Some news on the version 2: a new format of the soundfont will be available with a good enhancement on the time to load. But there is a lot of work to finish ;-)
    Best regards
     
    Last edited: Nov 21, 2018
  5. MattiHietanen

    MattiHietanen

    Joined:
    Nov 24, 2018
    Posts:
    13
    This is real cool stuff.
    Do you think that would be possible to receive Midi events from the midi driver in Unity and send back?

    Another interesting solution would be to have independent play notes timing with high precision timer. Perhaps first on Windows.

    The problem with playing notes is to wait exactly for the next time to play a note. It's possible with Time or Stopwatch, but if you do in an Wait Until ( Time > nextTime) you cook the cpu. :)

    Any idea how that can be done?
     
    Last edited: Nov 25, 2018
  6. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    hello
    There is no midi driver in Unity ;-) it's why I have build MPTK. Or you have to use dedicated framework for each platform. Not useful!
    With MPTK, midi is read every 10 ms to check if there is some available notes to play.. This much less than the capacity of perception of our brain between two notes : 25 ms ... and the CPU is not cook! Of course, the read is done in a CoRoutine to let Unity make others jobs. Have a look to the code in MidiPlayer.cs function ThreadPlay.
    BR
    Thierry
     
  7. MattiHietanen

    MattiHietanen

    Joined:
    Nov 24, 2018
    Posts:
    13
    Did you measure the time in update and and call the CoRoutine?
    Thank you.
     
  8. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Not sure to well understand your question. But I try: the update is not use by MPTK, only coroutine is used to play music. The time spend in coroutine depends on the lengh of the note of course, the CPU load is quite low. Have a look to the code of the free version !
    BR
    Thierry
     
  9. otomus

    otomus

    Joined:
    Nov 30, 2018
    Posts:
    1
    Hello
    I was impressed with this tool kit! Thank you for your effort.
    I am examining to purchase pro version. Does MidiFileWriter need original Midi File?
    I am developing simple musical composition game. I would like to create Midi File only from my code. Does pro version support it?
     
    wetcircuit likes this.
  10. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hello otomus
    Yes ! MPTK can write standard midi file from new. See below test code available in Pro version with the TestMidiWriter scene.
    There is a piano keyboard and a very simple sequencer use to check the API. When you click on key (as Unity button), note+velocity+duration are stored in a sequence. PatchChange are also process. Then the sequence is writed as a midi file.

    BR
    Thierry

    Code (CSharp):
    1.   /// <summary>
    2.         /// Create a Midi file from the PianoTrack sequence
    3.         /// </summary>
    4.         private void CreateMidiFromSequence()
    5.         {
    6.             int lastPatch = -1;
    7.  
    8.             // Create a midi file writer.
    9.             MPTK_MidiFileWriter mfw = new MPTK_MidiFileWriter(PianoTrack.ticksPerQuarterNote, 1);
    10.  
    11.             // First track (index=0) is a general midi information track. By convention contains no noteon
    12.             // Second track (index=1) will contains the notes
    13.             mfw.MPTK_CreateTrack(2);
    14.  
    15.             // Some textual information added to the track 0
    16.             mfw.MPTK_AddEvent(0, new TextEvent("Midi Sequence by MPTK/NAudio", MetaEventType.SequenceTrackName, 0));
    17.  
    18.             // TimeSignatureEvent (not mandatory) exposes
    19.             //      Numerator(number of beats in a bar),
    20.             //      Denominator(which is confusingly in 'beat units' so 1 means 2, 2 means 4(crochet), 3 means 8(quaver), 4 means 16 and 5 means 32),
    21.             //      as well as TicksInMetronomeClick and No32ndNotesInQuarterNote.
    22.             mfw.MPTK_AddEvent(0, new TimeSignatureEvent(0, 4, 2, 24, 32));
    23.  
    24.             // Default tempo of playing (not mandatory)
    25.             mfw.MPTK_AddEvent(0, new TempoEvent(MPTK_MidiFileWriter.MPTK_GetMicrosecondsPerQuaterNote(PianoTrack.beatsPerMinute), 0));
    26.  
    27.             foreach (KeyboardNote note in PianoTrack.Notes)
    28.             {
    29.                 long absoluteTime = (long)(note.TimeMs * PianoTrack.RatioMilliSecondToTick);
    30.                 if (lastPatch != note.Patch)
    31.                 {
    32.                     // Patch/preset to use for channel 1. Generally 0 means Grand Piano
    33.                     mfw.MPTK_AddEvent(0, new PatchChangeEvent(absoluteTime, note.Channel, note.Patch));
    34.                     lastPatch = note.Patch;
    35.                 }
    36.                 mfw.MPTK_AddNote(
    37.                     1,
    38.                     absoluteTime,
    39.                     note.Channel,
    40.                     note.Note,
    41.                     note.Velocity,
    42.                     (int)(note.Duration * PianoTrack.RatioMilliSecondToTick));
    43.             }
    44.  
    45.             // It's mandatory to close track
    46.             mfw.MPTK_EndTrack(0);
    47.             mfw.MPTK_EndTrack(1);
    48.  
    49.             // build the path + filename to the midi
    50.             string filename = Path.Combine(Application.persistentDataPath, "Generated Midi.mid");
    51.             Debug.Log("Write Midi " + filename);
    52.             // wrtite the midi file
    53.             mfw.MPTK_WriteToFile(filename);
    54.         }
     
    Last edited: Dec 5, 2018
    otomus likes this.
  11. ScottySR

    ScottySR

    Joined:
    Sep 29, 2018
    Posts:
    2
    Hi,

    Does this (or the pro version) have the following features?
    • Loop midi to a certain position (rather than very beginning)
    • Cut out other notes playing on the same channel regardless of if it's the same note or not (basically mono polyphony for channels) which also would affect the release part of the sample if there is one and one shot samples such as drums
    • Cut notes on selected channels when specific sound effects play depending on what sound effect plays
    Basically I'm making a game that looks and sounds similar to a NES game and I want to replicate the feeling of limited channels and sound effects "stealing" a channel from the music. If these features would exist then this would be exactly what I need for my project

    EDIT: I forgot to ask if a support for channel events such as channel volume, pan and pitch is possible (if it isn't already)? The modulation event would be useful as well to make vibratos more effortless to sequence in the midi files
     
    Last edited: Dec 8, 2018
  12. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hi
    A lot of interesting questions !
    MPTK V1 is a light Midi Player. Not all the midi standard are implemented. The goal was to be able to play simple Midi file sound on weak device. To be short, these functions are in V1:
    • pan, volume and patch are managed by channel
    • wave are selected by split key and velocities
    • mode loop are managed
    • envelope volume are managed but with the minimal
    But not these functions:
    • exclusive class sound
    • generator
    • modulator
    • mono channel
    i'm working on a V2 more near of a midi synthesizer. I'm rewriting fluidsynth to C# and try to adapt to Unity. For now, generator and modulator are correct for the most part.

    BR
    Thierry
     
    Last edited: Dec 10, 2018
  13. affordableaudio

    affordableaudio

    Joined:
    Feb 8, 2012
    Posts:
    33
    Hi there.

    I recently tried out the free version, and got pretty excited about trying to set up my own custom sound font for a game i'm working on.
    So I bought the pro version, and got everything all figured out.

    But for the life of me, I just can't seem to get short notes to play properly on any sound font but the exact one you used. I went through a huge list of free sound fonts, and just cannot get short notes to play at all. Everything almost sounds like it is playing the entire wave file, but i'm not 100% positive.

    It feels like it's definitely on my end, but I'm just wondering if there is anything that i'm doing wrong, I feel like i'm going crazy.
    Anyway, luckily there is some other stuff I can work on for a while, but eventually I would like to solve this.
     
    BachmannT likes this.
  14. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hello
    Not sure to understand your issues. What do you mean by "short note" ? are you writing your own midi sequence ? Could you send me an extract of your code ?
    BR
    Thierry
     
  15. affordableaudio

    affordableaudio

    Joined:
    Feb 8, 2012
    Posts:
    33
    well there isn't any code changes i'm making.
    Simply using the Midi File Player Prefab, and trying to Play At startup at the moment.

    Here is a Google Drive link to a quick midi loop I wrote to test on.
    https://drive.google.com/file/d/17x2eZnG8IvNKI5E4wFraWlMtBHMgAf6T/view?usp=sharing

    It's just three piano banks playing a short loop of sixteenth notes.
    I don't intend to actually use this track, but I do intend to have lots of shorter notes play like this.

    And basically I would "Like" to start off with either one of these two sound fonts
    http://pphidden.wixsite.com/compifont,
    https://drive.google.com/file/d/1alSnxnB0JFE6mEGbUZwiYGxt2UsoO3pM/view
    and combine the best of the two using Polyphone, and find, or record a few more instruments if needed to suit my needs.

    But i'm getting the problem in Unity of none of the notes are playing short, they just sorta trail on.
     
  16. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Ok thank for this well documented issue. I have an idea of the error, I find a way to correct and let you inform ASAP !
    Best regards
    Thierry

    Edit: issue is identified.
    I will publish a new version, but there is a hack to correct your issue.

    Open the XML generated in the soundfont folder with a text editor (for example: .\Assets\MidiPlayer\Resources\SoundfontsDB\Compifont_13082016\Compifont_13082016.txt). Don't change anything but force to save the text file. The soundfont will be correctly detected by Unity.

    One bad news: the soundfont Compifont seems plays bad for some midi (too complex soundfont ?)
    One good news: the soundfont Compifont plays good with the future V2 (beta test available in january, i hope)

    MPTK V2 is a complete rewrite of the synth engine based on fluidsynth: better performance on loading (x20) and better sound experience for the most part of midi files..

    Have a nice days
    Thierry
     
    Last edited: Dec 11, 2018
  17. affordableaudio

    affordableaudio

    Joined:
    Feb 8, 2012
    Posts:
    33
    Thank you for taking the time to look into it!

    For now, i'll use the XML fix you mentioned.

    The MPTK V2 sounds great too! Looking forward to it.
     
  18. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hello
    Version 1.96 is published to Unity. Will be available next week, depending of the loading of the Unity's team.
    Thank for your comment on the Unity store, it's very important for me to get encouraged ! It's a lot of work !
    Have a nice day.
    Thierry
     
  19. roypon11

    roypon11

    Joined:
    Feb 5, 2018
    Posts:
    1
    Hi, I'm using the free version of MPTK to make a procedural music generator. I previously made one in a Java library called JFugue but I've decided to just make one from scratch again, as opposed to trying to make Java and Unity cooperate. I also consider myself a beginner to the Unity engine, I started using it maybe a year ago.

    Your addon works online! As in, it can be exported into Unity WebGL, and it doesn't lose functionality! Which makes it a good alternative to using Javascript to get MIDI to work online. I didn't do an extensive test though. I just made a quick build for TestMidiStream and it seemed to work fine.

    I couldn't get InfinityMusic to work, no sound is produced. When I add the two components, MathMotif and Cadence, and try again, it appears the InfinityMusic object prefab destroys itself.

    Big fan of the project.
     
  20. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    40
    Hello
    Thank to appreciate MPTK !
    InfinityMusic does not work outside the Unity Editor. So you can't execute it in a standalone application. Some change have to be done. My first intention was to remove this demo from MPTK V2 (available in January) but I could reconsider this decision if you are interested. Have you some link to your WebGl demo ?
    Best regards
    Thierry