Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

New V2.7 new functions, better accuracy

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

  1. URGr8

    URGr8

    Joined:
    Sep 10, 2012
    Posts:
    16
    Hi Thierry,
    I had a question on V2 of MPTK, If I play middle C from a midi file, is that C3 or C4, or Send a NoteOn event to the Midistream player with value of 60. Will that be Octave 3 or 4?
     
  2. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hello
    It's C4
    A tip:
    Activate Log Waves with the MidiStreamPlayer Prefab:
    upload_2020-2-8_7-42-57.png
    Play a note with TestMidiStream or other, you see the sample plays for each notes.
    upload_2020-2-8_7-43-40.png

    Best Regards
    Thierry
     
  3. alezfdezgar

    alezfdezgar

    Joined:
    Feb 27, 2020
    Posts:
    3
    Hi Thierry.
    I have a doubt. How can I do recognise a image target and play the midi? I have to do a project for end my college career.
     
    Last edited: Feb 27, 2020
  4. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hello
    I'm not sure to understand
    recognise a image: sorry it's not the goal of MPTK.
    Launch a midi from script: easy !
    Code (CSharp):
    1.  // assign the prefab MidiFilePlayer from your hierarchy to this properties in your inspector
    2. public MidiFilePlayer midiFilePlayer;
    3.             ...
    4. midiFilePlayer.MPTK_MidiIndex = midiindex;
    5. midiFilePlayer.MPTK_Play();
    See here for more informations: https://paxstellar.fr/midi-file-player-detailed-view-2

    Best regards
     
    Last edited: Feb 27, 2020
  5. alezfdezgar

    alezfdezgar

    Joined:
    Feb 27, 2020
    Posts:
    3
    Hello,
    Thanks you for the information. Sorry for not explaining me well. I speak English a little.
    I have a doubt. For my end-of-degree work, I need to know how it is done, for an augmented reality application, to recognize a marker (in my case a photo) with the camera and that it plays a MIDI while the marker is being recognized. When the marker disappears from the scene, do not play anything. I'm trying to know how it's done but I can't get it.

    Thank you so much for everything. I am looking forward to your response

    Best regards







     
    Last edited: Mar 4, 2020
  6. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hi,
    Yes I understand your need. But this thread is not the good place for your question. Try dedicated thread about AR. Then to play a midi it's very easy. See my previous post.
     
  7. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    Hello,

    Downloaded today, and been tinkering, got it working great on standalone for PC. However, for WebGL, I'm running into issues. Unity wants to change all Audio Clips to 'Decompress on Load", which causes a large number of them to become distorted and unusable. For reference, I've been attempting the "TestMidiStream" scene file.

    Have you had any success running this asset on WebGL, and if so are there any tips to convert over?

    Thanks
     
  8. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hello
    Thank for your interest with MPTK. I apologize, but MPTK is not running on WebGL. See here : https://paxstellar.fr/2019/03/25/platform-compliance/
    Best Regards
    Thierry
     
  9. IPnose

    IPnose

    Joined:
    Jun 6, 2014
    Posts:
    20
    I haven't tested it yet, but your asset looks fantastic.

    I'll most likely use it to port to Android an old application I had developed for Windows 8 ; https://www.microsoft.com/en-us/p/my-masterpiece/9wzdncrddp2c (no midi support, each note of each instrument had been extracted manually, it was quite laborious for an average result).
     
  10. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hi
    Sound very interesting ! Keep me inform and contact me if question.
    Regards
    Thierry
     
  11. MrKendi

    MrKendi

    Joined:
    Feb 15, 2019
    Posts:
    5
    Hi Thierry, Thanks for great asset, I tried demo version and later bought pro version. Unfortunately after upgrading from 2.5 to 2.7 MTKP is not reading properly events around 1:01 (first notes, track information, lyrics etc). Whats more , its not reading for 99% times, sometimes I can see it could read one track name. Everything works fine in 2.5

    EDIT, I also noticed that next two notes (A5 B4) that are on 1:01:001 and 002 are shown in console log, but for 9/10 replays they are mute (sometimes only one), but they are 100% played when player is set to loop and restarts playing
     

    Attached Files:

    Last edited: Mar 9, 2020
  12. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hello MrKendi
    Could you send me your midi ?
    What desktop are you using ? Mac / PC ?
     
  13. MrKendi

    MrKendi

    Joined:
    Feb 15, 2019
    Posts:
    5
    In attachment you can find my test midi file, there is one chord at the beginning (each note separated by one tick:000,001,002) And also lyrics for each tick ("0" for 1: 01:000, "1" for 1:01:001..)
    EDIT - I'm on PC
     

    Attached Files:

    Last edited: Mar 9, 2020
  14. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Ok, I understand. The first three notes (C4, A5, B4) are not played unless the loop mode is activated. It's a bug, I apologize for that.
    Generally Midi starts after some ticks and not so early (0,1,2 ticks here). Try to start playing after a tick > 500 or after 0.5 second.
    Of course, I will correct this issue ASAP.
    Thank for this information.
    Best Regards
    Thierry
     
  15. MrKendi

    MrKendi

    Joined:
    Feb 15, 2019
    Posts:
    5
    There are two different problems, one is that none of the information written at 1.1.000
    has been read (title, track names etc). I can always move first notes a little, but the problem is with track names, which are very important for me.
    (there is no difference with loop mode)

    Secondly, notes that are in next tick (001,002) are shown properly in console, but they are muted. But if activate loop, and loop is restarting, then I can hear them. This is also important for me because i want to use short midi in loops

    Both problems are not 100% constant, when I hi stop/play many times I can sometimes see some track information, or hear first notes
    Also in version 2.5 everything works fine
     
  16. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hi, yes all these issues come from the same problem: early events are not read; track name, notes, ... unless when looping or sometimes. For now, I did'nt found the root cause. I'm searching ....
     
  17. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hello, random bug are the worst ! but it's ok I found the cause.
    Currently delay for publishing are quite long (>10 days). I will explain what to modify.

    Open source file MidiFilePlayer.cs,
    Uncomment line 1108
    Comment line 1109
    upload_2020-3-11_22-33-13.png

    like this:
    upload_2020-3-11_22-34-19.png

    And that will be good !

    BR
    Thierry
     
    Last edited: Mar 12, 2020
  18. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    V2.71 is now available with the correction.
     
    Last edited: Mar 16, 2020
    MrKendi likes this.
  19. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    18
    I've finally gotten around to implementing this into my project and I'm loving it! I do have a question though. Is it possible to mute or change the volume of individual MIDI channels? I'd love to be able to dynamically mute and unmute channels in my game's soundtrack depending on what's going on. For example, a level could start out with just a piano playing on channel 1, and then later I could turn on a channel for trumpets, and then drums, etc. Unless I'm missing something, currently it seems the only way I'd be able to do something like that would be by making separate MIDI files with the different combinations of tracks I want, but of course that would require me to restart playback every time I wanted to introduce a track which would completely ruin the flow of the music.

    If that's not currently possible, it's a feature I'd love to see added!
     
  20. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hello
    Good to known you succeed!
    I'm sorry but the function you need don't exist for now with MPTK. It's only possible to enable or disable channel in real time.
    But it's a very good idea, I will see how to add this function for a new release.
    Best Regards
    Thierry

    PS: see the demo:TestMidiFilePlayerScripting
    upload_2020-5-6_8-38-42.png
    And the API:
    Code (CSharp):
    1.  
    2.                 GUILayout.BeginHorizontal();
    3.                 for (int channel = 0; channel < midiFilePlayer.[B]MPTK_ChannelCount[/B](); channel++)
    4.                 {
    5.  
    6.                     bool state = GUILayout.Toggle(midiFilePlayer.[B]MPTK_ChannelEnableGet[/B](channel),
    7.                                string.Format("{0} / {1}", channel + 1,
    8.                                       midiFilePlayer.[B]MPTK_ChannelPresetGetIndex[/B](channel)), GUILayout.Width(65));
    9.                     if (state != midiFilePlayer.[B]MPTK_ChannelEnableGet[/B](channel))
    10.                     {
    11.                         midiFilePlayer.[B]MPTK_ChannelEnableSet[/B](channel, state);
    12.                         Debug.LogFormat("Channel {0} state:{1}, preset:{2}",
    13.                                     channel + 1, state,
    14.                                     midiFilePlayer.[B]MPTK_ChannelPresetGetName[/B](channel) ?? "not set");
    15.                     }
    16.  
    17.                     if (channel == 7)
    18.                     {
    19.                         // Create a new line ...
    20.                         GUILayout.EndHorizontal();
    21.                         GUILayout.BeginHorizontal();
    22.                     }
    23.                 }
    24.                 GUILayout.EndHorizontal();
    25.  
     
  21. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    18
    Ah, MPTK_ChannelEnableSet was exactly what I was looking for! While the ability to control the volume of individual channels would be cool I was mainly concerned about turning them on and off. Thanks for the help!
     
  22. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Ready for the next version ;-)
    upload_2020-5-7_8-19-2.png
     
  23. EvanXu1225

    EvanXu1225

    Joined:
    Dec 6, 2019
    Posts:
    1
    Hi Bachmann, I spent two weeks looking for a suitable plugin for my app and I finally find it. I am making an instrument app. People can play the instrument by click or enter the string on the screen. However, there is a problem for one of the function. I want to make the string change color as the instrument in the song plays. Is there any way to realize this using your Plugin?
     
  24. BachmannT

    BachmannT

    Joined:
    Nov 20, 2016
    Posts:
    126
    Hi
    Yes you can do that, but only by scripting:

    First method, detect Midi event PatchChange, example:
    Code (CSharp):
    1. midiFilePlayer.OnEventNotesMidi.AddListener(NotesToPlay);
    2.   public void NotesToPlay(List<MPTKEvent> notes)
    3.         {
    4.             countZ = new int[Convert.ToInt32(maxZ - minZ) + 1];
    5.  
    6.             //Debug.Log(midiFilePlayer.MPTK_PlayTime.ToString() + " count:" + notes.Count);
    7.             foreach (MPTKEvent note in notes)
    8.             {
    9.                 switch (note.Command)
    10.                 {
    11.                     case MPTKCommand.NoteOn:
    12.                         if (note.Value > 40 && note.Value < 100 && note.Channel==1)
    13.                         {
    14.                            // some actions
    15.                         }
    16.                         break;
    17.  
    18.                     case MPTKCommand.PatchChange:
    19.                         {
    20.                            // some actions
    21.                         }
    22.                         break;
    23.                 }
    24.             }
    25.         }
    26.  
    27.  
    Or read the current instrument associated to a channel. Example.:
    Code (CSharp):
    1. textPlayer.text =
    2.                     //$"Channel:{midiFilePlayer.DedicatedChannel} - " +
    3.                     $"{midiFilePlayer.MPTK_ChannelPresetGetIndex(midiFilePlayer.DedicatedChannel)} - " +
    4.                     $"{midiFilePlayer.MPTK_ChannelPresetGetName(midiFilePlayer.DedicatedChannel)}\n" +
    5.                     $"{midiFilePlayer.MPTK_StatVoicePlayed.ToString()}";
     
unityunity