[LIB] Play MIDI files with your plugin!

Discussion in 'Resources' started by authorblues, May 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    authorblues

    Ever wanted your plugin to play MIDI files for players to listen to? Ever wanted to punish players by being trapped in a bedrock box playing nevergonnagiveyouup.mid on repeat until they apologize for greifing that one half-assed house the server owner's girlfriend made? Do you wanna make more money? Sure, we all do! Now you can do some or none of these things!

    The following library for midi sequencing is provided as-is, without guarantees or decoration. You are free to use it as you wish, though I ask that you leave the @author attribution in the code if you make it open source. To use it, include it in your plugin (obviously change the package name at the top to match your source code, unless you are also developing a plugin in the org.mctourney.autoreferee namespace, in which case, we should talk!)

    Bukkit MIDI sequencing - Courtesy of AutoReferee

    To use, simply call the MidiUtil.playMidi() or MidiUtil.playMidiQuietly() functions (the only difference is that playMidiQuietly will not throw exceptions, but will return true if it executed without error, and false otherwise). Both accept a file (the midi file), a tempo factor (0.5f for half speed, 2.0f for double speed, etc), and a Set of Players who should hear the track.

    If you find any bugs in the code, please let me know. Otherwise, I hope this helps some or none of you.
     
    TigerHix, creepers84, Skyost and 7 others like this.
  2. Offline

    Me4502

  3. Offline

    authorblues

    What makes your method better? I am using the built in javax midi sequencer to handle and delegate the NOTE_ON events, whereas you have a BukkitRunnable that is executing a repeating task trying to emulate what already exists? The only difference, it seems, is that you implement multiple instruments, while my version (hastily-assembled) just uses the PIANO instrument.

    Not that there is anything wrong with you doing it that way, but it seems unnecessary, so I don't see why that way is better.
     
  4. Offline

    Me4502


    I am talking about the instruments and extra octaves... Not the way it's done.

    Edit: And the lack of noteblocks required.

    Edit 2: Wait a second.. What BukkitRunnable are you talking about?
     
  5. Offline

    Skyost

    How can we use this ?
     
  6. Offline

    gomeow

    Very nice.
    Although, the sequencer can use an InputStream, which seems preferable, since we can use getResource()
     
  7. Offline

    Hogcraft

    authorblues is there a way to stop the music from playing?
     
  8. Offline

    iZanax

    authorblues

    I got some a few question over this Util.
    - Is it thread safe ?
    - Does it need a tempo, since .midi files have already a tempo, if I remember right.
    - Can we set it do only 1 run with 'sequencer.setLoopCount(1);' ?? (so it stops after it's done)

    Thanks in advance
     
  9. Offline

    Freack100

    Is there a way to have it shuffle through a folder?
     
    DrJava likes this.
  10. Offline

    DrJava

  11. Offline

    creepers84

    How do we play the file to the player? + Where do we save it?
    Since your the only one online, iZanax do you know?
     
  12. Offline

    Phasesaber

    I am working on something like this, but it uses like 5 different notes.
     
Thread Status:
Not open for further replies.

Share This Page