Playing two midi files at once using threads?

Hi all, I have the following simple code here which plays a midi file, but I'm not sure how to use threads to play two midi files at once:
import org.jfugue.*;
import javax.sound.midi.*;
import java.io.*;
public class MidiPlayer {
public static void main (String [] args) {
try {
Player player = new Player();
player.playMidiDirectly(new File("C:\\Sounds\\bach.mid"));
} catch (IOException e) {
} catch (InvalidMidiDataException e) {
Is there a way to use a thread for this class so that in another class I can call 'start' twice and have the parameters be the midi file locations (e.g. "C:\\Sounds\\bach.mid" & "C:\\Sounds\\bach2.mid").
Any kind of help would be great, thank you!

Something like the below.
import org.jfugue.*;
import javax.sound.midi.*;
import java.io.*;
public class MidiPlayer {
public static void main (String [] args) {
String fileName = "c:\\Sounds\\bach.mid";
Thread t1 = new Thread(new MyRunable(fileName));
t1.start();
String fileName2 = "c:\\Sounds\\bach2.mid";
Thread t2 = new Thread(new MyRunable(fileName2));
t2.start();
} // main
class MyRunnable implements Runnable {
private String fileName
public MyRunnable( String fileName) {
  this.fileName = fileName;
   public void run() {
     Player player = new Player();
    player.playMidiDirectly(new File(fileName));
} // MyRunnable
} //

Similar Messages

  • Mixing two midi files using j2me

    I have build an application for playing the midi files and also concatinate midi files......i want to build an application for mixing the midi files using j2me....Can anyu one please help me in doing this..........
    Thanks

    This should help you on your way:
    http://jedi.ks.uiuc.edu/~johns/links/music/midifile.html

  • How do i play two sound file one after another

    Hi All,
    How do i play two sound file one after another using single AudioClip Component?.
    Advance in thanks
    Manivel

    AudioClip gives you very little control over what happens to the sound, it also isn't capable of playing long clips or waiting until a clip ends. It will play multiple clips over top of each other.
    To do what you want you should use the facilities of javax.sound. Here's a post with an example: http://forum.java.sun.com/thread.jspa?forumID=513&threadID=450768
    There is also a tutorial, but its example fails for long clips.

  • Play two video files at the same time.

    I am trying to play two video files at the same time. I create two threads, each of which has its own frame, playing button, and builds its own graph to play the file. Now everything seems works except that when the first file is being played and I hit PLAY
    to play the second file, the program plays the second file but the first one is paused; furthermore the control button has no response for the first one. Did I miss anything? Can anyone help me figure out the problem?
    Best,
    Fayin

    You don't need separate threads for 2+ playback pipelines because the filters create worker threads internally and don't block execution on calling thread.
    If you decide to keep separate threads, you will have to follow Michel's advice and have message pumps on those threads.
    You can also have both files in the same graph, in which case you have perfect sync between them (both start playing together in sync), however you cannot pause/stop/run files separately.
    The problem you described is most likely not a DirectShow problem and is rather about generic threading, COM or window messaging.
    http://alax.info/blog/tag/directshow

  • Is there a way to play a MIDI file?

    I would love to use Mainstage2 but is there any way to play a midi file now? I have an external DMX controller that gets it commands from MIDI and is programed to match the playback tracks. So far my only solutions have been to use Ableton LIVE or DP.
    Thanks
    Chris

    If you're still looking for a solution to this problem, you should try out the newest version of SysEx Librarian (http://www.snoize.com/SysExLibrarian/). There is an option in the preferences to enable a column where you can set a program change number per sysex (midi) file. Then you can set MainStage to route midi program changes to SysEx Librarian, and whenever a program change gets sent out (either by a mapping or because you switched patches) it will play out the midi. Works great for me!

  • Is it possible to play two audio files simultaneously.

    Hi,
    Is it possible to play two audio files simultaneously.
    I modified the 'SpeakHere' to play two audio files simultaneously, it worked perfectly on simulator but get hanged on iphone.
    To this I implemented NSTimer, which regularly checks for both player instance every second.As soon as any player gets stopped Timer task stops the second one forcefully and again starts both.
    thanks.

    Hi Jay
    Do you have the eLearning Suite? If so, you have Adobe Presenter available to you. If you don't, you should be able to download the Presenter installation file and evaluate it.
    Presenter is an add in for PowerPoint. The neat thing about it is that it provides for a Table of Contents type of functionality as you see is configured in Captivate. But the twist with that is you are able to do something you cannot do in Captivate. You are able to insert videos inside the TOC area!
    Just musing out loud... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Playing two midi keyboards at the same time in logic for live show

    hello, i have a macbook pro 2.16 cpu, os 10.4.7, logic 7.1.1 and 7.2 is on the way
    1 gb of ram
    a tascma us-428 inerface
    i want to be able to play two diffrent midi keyboards at the same time is their a way to have one digital instrament for on keyboard, and another midi keyboard on a diffrent digital instrament at the same time, so as to play a live show?
    and also if i want to chang the intrament in the middle of a song becase it switches half way throw the song, is it posble to atomate this switch insted of doing it by hand? please help! thank you.

    here is some good reading regarding patch change
    http://discussions.apple.com/thread.jspa?messageID=2931940&#2931940
    http://discussions.apple.com/thread.jspa?messageID=1993033&#1993033
    http://www.logicprohelp.com/viewtopic.php?t=1045&highlight=instrumentprogram+programmechange

  • Why does Quicktime 7.1 Pro stop playing my .MID files after only 30-40 secs

    My MIDI files have the sustain pedal permanently depressed, and after 30 - 40 seconds, Quicktime 7.1 Pro goes silent when replaying them. This does not happen on other computers such as Windows XP using a Soundblaster card. I assume that it is a fault with Quicktime. If I click on pause, then play, then playback resumes for a while and then cuts out again.

    More details. Running on Windows, CPU usage climbs steadily to 100% then the music cuts out. CPU usage remains at 100%. Running on a MacBook, CPU usage climbs to 25%, then the music cuts out. CPU usage remains at 25% until the end of the MIDI playback. This problem applies to Quicktime for Macintosh and Quicktime for Windows.

  • How can I print multiple PDF files at once using Windows 7?

    How can I print multiple PDF files at once, on an HP LJ Pro 400 xcolocr printer without opening each
    one separately using Windows 7?

    I am sorry, but to get your issue more exposure I would suggest posting it in the commercial forums since this is a commercial printer. You can do this at http://h30499.www3.hp.com/hpeb/
    I hope this helps.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Add bookmarks to all pdf files at once using javascript or apple script

    Hello
    I have a folder containing pdf files of a survey.
    There is also a 'surveyname.pdf' file which consists of a number of pages.
    These pages have to be bookmarked for easy reference.There is a 'dummy.pdf' file which has all the bookmarks of the survey pages. I am using Adobe Acrobat 7.0 to open this file.
    There are also some map pdf's in the same folder.
    How can I add the bookmarks that are in the 'dummy.pdf' file to all the other pdf files in the same folder at once instead of doing one at a time which consumes a lot of time for 100-120 files?
    I use extendscript toolkit for writing the javscript or applescript code.
    I would be grateful if anyone could help me in solving this.
    Thankyou
    Krishna

    Here are some examples of doing the insert and the save in a separate operation. You can put them together on your own.
    ~T
    //From the JS Reference:
    this.insertPages ({
    nPage: -1,
    cPath: "/c/temp/myCoverPage.pdf",
    nStart: 0
    //Example of a trustedFunction SaveAs
    mySaveAs = app.trustedFunction(function (cPath)
    app.beginPriv();
    this.saveAs(cPath);
    app.endPriv();
    app.addMenuItem({ cName: "mySaveAs", cParent: "Insert Page",
    cExec: "mySaveAs('/c/myFolder/myNewPDF.pdf')",
    cEnable: "event.rc = (event.target != null);",
    nPos: 0

  • Playing a wav file (byte array) using JMF

    Hi,
    I want to play a wav file in form of a byte array using JMF. I have 2 classes, MyDataSource and MyPullBufferStream. MyDataSource class is inherited from PullStreamDataSource, and MyPullBufferStream is derived from PullBufferStream. When I run the following piece of code, I got an error saying "EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9108b2, pid=3800, tid=1111". Any idea what might be the problem? Thanks.
    File file = new File(filename);
    byte[] data = FileUtils.readFileToByteArray(file);
    MyDataSource ds = new MyDataSource(data);
    ds.connect();
    try
        player = Manager.createPlayer(ds);
    catch (NoPlayerException e)
        e.printStackTrace();
    if (player != null)
         this.filename = filename;
         JMFrame jmframe = new JMFrame(player, filename);
        desktop.add(jmframe);
    import java.io.IOException;
    import javax.media.Time;
    import javax.media.protocol.PullBufferDataSource;
    import javax.media.protocol.PullBufferStream;
    public class MyDataSource extends PullBufferDataSource
        protected Object[] controls = new Object[0];
        protected boolean started = false;
        protected String contentType = "raw";
        protected boolean connected = false;
        protected Time duration = DURATION_UNKNOWN;
        protected PullBufferStream[] streams = null;
        protected PullBufferStream stream = null;
        protected final byte[] data;
        public MyDataSource(final byte[] data)
            this.data = data;
        public String getContentType()
            if (!connected)
                System.err.println("Error: DataSource not connected");
                return null;
            return contentType;
        public void connect() throws IOException
            if (connected)
                return;
            stream = new MyPullBufferStream(data);
            streams = new MyPullBufferStream[1];
            streams[0] = this.stream;
            connected = true;
        public void disconnect()
            try
                if (started)
                    stop();
            catch (IOException e)
            connected = false;
        public void start() throws IOException
            // we need to throw error if connect() has not been called
            if (!connected)
                throw new java.lang.Error(
                        "DataSource must be connected before it can be started");
            if (started)
                return;
            started = true;
        public void stop() throws IOException
            if (!connected || !started)
                return;
            started = false;
        public Object[] getControls()
            return controls;
        public Object getControl(String controlType)
            try
                Class cls = Class.forName(controlType);
                Object cs[] = getControls();
                for (int i = 0; i < cs.length; i++)
                    if (cls.isInstance(cs))
    return cs[i];
    return null;
    catch (Exception e)
    // no such controlType or such control
    return null;
    public Time getDuration()
    return duration;
    public PullBufferStream[] getStreams()
    if (streams == null)
    streams = new MyPullBufferStream[1];
    stream = streams[0] = new MyPullBufferStream(data);
    return streams;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import javax.media.Buffer;
    import javax.media.Control;
    import javax.media.Format;
    import javax.media.format.AudioFormat;
    import javax.media.protocol.ContentDescriptor;
    import javax.media.protocol.PullBufferStream;
    public class MyPullBufferStream implements PullBufferStream
    private static final int BLOCK_SIZE = 500;
    protected final ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW);
    protected AudioFormat audioFormat = new AudioFormat(AudioFormat.GSM_MS, 8000.0, 8, 1,
    Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8, Format.NOT_SPECIFIED,
    Format.byteArray);
    private int seqNo = 0;
    private final byte[] data;
    private final ByteArrayInputStream bais;
    protected Control[] controls = new Control[0];
    public MyPullBufferStream(final byte[] data)
    this.data = data;
    bais = new ByteArrayInputStream(data);
    public Format getFormat()
    return audioFormat;
    public void read(Buffer buffer) throws IOException
    synchronized (this)
    Object outdata = buffer.getData();
    if (outdata == null || !(outdata.getClass() == Format.byteArray)
    || ((byte[]) outdata).length < BLOCK_SIZE)
    outdata = new byte[BLOCK_SIZE];
    buffer.setData(outdata);
    byte[] data = (byte[])buffer.getData();
    int bytes = bais.read(data);
    buffer.setData(data);
    buffer.setFormat(audioFormat);
    buffer.setTimeStamp(System.currentTimeMillis());
    buffer.setSequenceNumber(seqNo);
    buffer.setLength(BLOCK_SIZE);
    buffer.setFlags(0);
    buffer.setHeader(null);
    seqNo++;
    public boolean willReadBlock()
    return bais.available() > 0;
    public boolean endOfStream()
    return willReadBlock();
    public ContentDescriptor getContentDescriptor()
    return cd;
    public long getContentLength()
    return (long)data.length;
    public Object getControl(String controlType)
    try
    Class cls = Class.forName(controlType);
    Object cs[] = getControls();
    for (int i = 0; i < cs.length; i++)
    if (cls.isInstance(cs[i]))
    return cs[i];
    return null;
    catch (Exception e)
    // no such controlType or such control
    return null;
    public Object[] getControls()
    return controls;

    Here's some additional information. After making the following changes to MyPullBufferStream class, I can play a wav file with gsm-ms encoding with one issue: the wav file is played many times faster.
    protected AudioFormat audioFormat = new AudioFormat(AudioFormat.GSM, 8000.0, 8, 1,
                Format.NOT_SPECIFIED, AudioFormat.SIGNED, 8, Format.NOT_SPECIFIED,
                Format.byteArray);
    // put the entire byte array into the buffer in one shot instead of
    // giving a portion of it multiple times
    public void read(Buffer buffer) throws IOException
            synchronized (this)
                Object outdata = buffer.getData();
                if (outdata == null || !(outdata.getClass() == Format.byteArray)
                        || ((byte[]) outdata).length < BLOCK_SIZE)
                    outdata = new byte[BLOCK_SIZE];
                    buffer.setData(outdata);
                buffer.setLength(this.data.length);
                buffer.setOffset(0);
                buffer.setFormat(audioFormat);
                buffer.setData(this.data);
                seqNo++;
        }

  • Playing .MOV MIDI files in iTunes 10.4

    In November last year I saved hundreds of old piano roll MIDI files in QuickTime format and added them to my iTunes library. They played quite happily in iTunes on the Snow Leopard OS.  I have just updated to Lion and now the new version of iTunes 10.4 will not play them. I get this error message:
    This movie requires QuickTime, which is not supported by this version of iTunes.
    Why would they remove functionality from iTunes in this way and no longer support MOV files in iTunes? Seems a retrograde step to me.  Does anyone know what I can do to restore my functionality. I spent days getting the metadata right for these files and do not want to lose my work.
    Thanks in advance for any suggestions or a solution.
    Steve

    Ah, I have resolved this myself by opening iTunes in 32-bit mode. Now plays these midi MOV files okay. How annoying that they did not provide inbuilt support for this in 64-bit in the Lion release. I assume no-one at Apple considered it a possibility...

  • When I Try to play a midi file, I get this message "Error Code AccessDenied /Code Message Access Denied /Message RequestId BAE3798FA4D46B8A /RequestId HostId 8/M6nE8bFEzqkHuBNZbWlYORnQ2r9tRDha/3noYE8aofln2RXtxxaotT5RXGPGHp /HostId /Error "

    I Like to download midi files and I always get this message, no problem however with Safari.
    Model Name: Mac Pro Mac OS 10.6.8
    Model Identifier: MacPro1,1
    Processor Name: Dual-Core Intel Xeon
    Processor Speed: 2.66 GHz
    Number Of Processors: 2
    Total Number Of Cores: 4
    L2 Cache (per processor): 4 MB
    Memory: 9 GB

    Right-click the link and use "Save Link as" to save the file if you can't open or save the link with a left-click.

  • Playing two FLV files simultaneously

    Hi all --
    Need a little help with my video player. Currently, I have
    one video (with an alpha channel) playing in the foreground.
    Embedded in that video are event cue points. When a specific cue
    point is reached, I would like a second video to start playing in
    the background. I've been unable to get this to work.
    I know my cue points are being recognized because I am doing
    a trace and they pop up. However, my video does not play.
    I may be using the wrong method, but currently I am using a
    second netConnection to play the video into a second video object.
    This obviously doesn't work.
    Please help!

    Thanks for your help everyone... here's the code. I'm trying
    to get a video to start playing when cue point "3" is reached in
    the first video...

  • Play a wav file once

    how do I play a wav file just once using the play sound
    file.vi. i keep getting it to repeat over and over
    thanks

    First may I recommend some reading here. This is not meant to be cocky just to help you.  
    Getting Started with NI LabVIEW Student Training
    LabVIEW101
    Second I have included sort of template. Notice the wire that ends in the while loop. This will ensure that the wav is played before the loop starts.
    Good luck with your Labview labwork
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    play wav file[2].vi ‏9 KB

Maybe you are looking for

  • Passing plsql parm to a sql statement in the procedure  database link name

    Would like to pass a parm that is the database link name to a stored procedure.  I defined this as below. var1 is the name of the db link that I would like to pass create or replace procedure   proc1  (var1 in varchar2) as cursor c1 is select num,nam

  • Rented a movie and it's not letting me watch it!

    I rented a movie off iTunes and now I want to watch it but it says 'this content is not authorised.' What do I do?

  • How to make a loading circle?

    Hi there. I want to do a loading circle in Expression Design (or Blend), but I don't really know how though. So I though I could ask in the expression forum =). What I mean by "loading circle", here's a good code project article showing the different

  • Incomplete print dIalog box when printing PDFs

    During the past several weeks, whenever I try to print a PDF, the print dialog box (when Copies & Pages is selected in the pull-down menu) is blank ... I can't select how many copies or which pages to print. This only started happening recently, befo

  • (GENIUS) Connecting iTouch to Car Stereo Head Unit

    Ok This one is for all of you wearing those black Genius T-Shirts I have an iTouch I am connecting it to my Pioneer DEH-6600 car stereo head unit I have connected it using the Pioneer CD-IB100 iPod Adapter Everything is working fine Though I an only