Meter changes in Java MIDI

I am writing a program that creates a midi file as output. This midifile can then be loaded into a sequencer and viewed as music notation.
The problem is that would like to know how to implement a meter change (ie time signature)
Can someone send me an example of some code that does this? I've ready the Sun java reference page extensively as well as many many other web pages, and all stop short of this topic.
Thanks

Here's the code I ended up using for creating and reading tempo change and time signature change messages. Note that Java doesn't support unsigned bytes, so when reading the value you have to check the sign before converting to int. Also, I haven't tested this with any outside equipment, just my own software synth.
code:
    final int TEMPO_MESSAGE = 0x51;
    MetaMessage tempoChangeMessage(int bpm) // bpm==beats per minute
         long mpq=60000000 / bpm; // mpq==microsec per quarter (beat)
         byte[] data = new byte[3];
         data[0] = (byte)((mpq >> 16) & 0xFF);
         data[1] = (byte)((mpq >> 8) & 0xFF);
         data[2] = (byte)(mpq & 0xFF);
         MetaMessage m = new MetaMessage();
         try
              m.setMessage(TEMPO_MESSAGE, data, data.length);
         catch (InvalidMidiDataException e)
         return m;
    boolean isTempoChangeMessage(MidiMessage m)
         if (!(m instanceof MetaMessage))
              return false;
         return ((MetaMessage)m).getType() == TEMPO_MESSAGE;
    // returns beats (quarter notes) per minute
    int getTempoFromMessage(MetaMessage m)
         byte[] byteData = m.getData();
         int[] intData = new int[3];
         // fix for lack of unsigned byte type
         for (int i=0 ; i<3 ; ++i)
              if (byteData[i] < 0)
                   intData[i] = byteData[i] + 256;
              else
                   intData[i] = byteData;
     long mpq=(intData[0] << 16) + (intData[1] << 8) + (intData[2]);
     return (mpq == 0 ? 1 : (int)(60000000 / mpq));
// denominator = 2 ^ denominatorExponent, eg 6, 3 gives 6/8 time
final int TIME_SIGNATURE_MESSAGE = 0x58;
MetaMessage timeSignatureChangeMessage(int numerator, int denominatorExponent)
     byte[] data = new byte[4];
     data[0] = (new Integer(numerator)).byteValue();
     data[1] = (new Integer(denominatorExponent)).byteValue();
     data[2] = (new Integer(24)).byteValue(); // ignoring this
     data[3] = (new Integer(8)).byteValue(); // ignoring this
     MetaMessage m = new MetaMessage();
     try
          m.setMessage(TIME_SIGNATURE_MESSAGE, data, data.length);
     catch (InvalidMidiDataException e)
          // oh well...
     return m;
boolean isTimeSignatureChangeMessage(MidiMessage m)
     if (!(m instanceof MetaMessage))
          return false;
     return ((MetaMessage)m).getType() == TIME_SIGNATURE_MESSAGE;      
// returns numerator, assume 1/4 notes so ignore denominator exponent etc
int getTimeSignatureFromMessage(MetaMessage m)
     byte[] data = m.getData();
     return data[0];
int quarterNotesPerBar=getTimeSignatureFromMessage(m);

Similar Messages

  • How to change the java cup icon for all the JFrames?

    Hi,
    I would like to know if I can change the Java cup defult icon that appears in the upper left corner of the JFrames in one time, instead of setting the JFrame's icon in every created JFrame.
    Regards,
    Gabriel

    Then don't set the parent to null. If you don't want a parent, just set it to
    JOptionPane.showMessage(new IconFrame(), ...
    [\code]
    where IconFrame extends JFrame and sets the icon in it's constructor.  The optionpane will then use the icon from it's parent frame.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Changes in java file dont show up on site

    hi
    i'm using tomcat4 server.
    i use java jsp html files for developing the website.any changes to jsp files show up on refreshing the page but when i do changes in java files (which are called from jsp files) compile them and refresh the page the changes dont show up.
    even restarting the server didn't help.
    when i delete the .class file of that java code still the server runs when it is called from jsp file.
    it doesn't give filenotfound or classnotfound error which is expected in such case.
    can anybody plz tell me what to do

    Did you not overlook something, like putting a jar containing (previous versions of ) your classes to "lib" ?

  • Change the java program in *.exe

    how can i do to change my java program in a .exe file ? This could be useful if the user doesn't have the java runtime environment.

    Hello
    You can use third party softwares like
    PJ2Exe or sumthing like that
    search on google
    Rohan

  • Is it possible to change the tempo mid-song in GarageBand for iPad? And if so, how do you do it?, Is it possible to change the tempo mid-song in GarageBand for iPad? And if so, how do you do it?

    Is it possible to change the tempo mid-song in GarageBand for iPad? And if so, how do you do it?

    The tempo setting applies to the whole song, but only to the recorded midi instruments or loops. It's a bit of a kludge, but you could record different sections at different tempos, export each as an AIFF file, then glue them together in a new project.
    The same goes for the key.
    tt2

  • Change the java cup picture in the top left corner

    Does any one knows how to change the java cup picture in the top left corner of the frames and applets
    Thanks in advance

    Hi,
    I have the following code added and get this error:
    non-static method setIconImage(java.awt.Image) cannot be referenced from a static context
    private static void SetUpGUIApplication(){
            //This must be invoked before
            //creating the JFrame.  Native look and feels will be set here
            // Comment this out to see the differences
           FrmMain.setDefaultLookAndFeelDecorated(true);
            ImageIcon appIcon = new ImageIcon(getClass().getResource("resources/FLGCAN.ICO"));
            if (appIcon != null)
                    setIconImage(appIcon.getImage());
        }What does this mean when adding static verses non static?
    Thanks

  • SerialversionUID Changes in JAVA 5

    I have an application which has Serializable classes. The application works in a cluster environment where these classes get serialized and deserialized. None of the classes declare an serialVersionUID variable explicitly.
    My question is: Based on the changes in Serialization changes in JAVA 5, how do I decide whether I really need to declare serialVersionUID field explicitly for my classes?

    I am a colleague of Puneet's. The serialization is not something we do; it is something that a Servlet Container does for (to?) us. There is persistence of these objects, but it's "temporary persistence" in that it will not span any versions of anything. The persistence will never last more than a few hours.
    I think this explains why this has not been an issue for us, and why we have not been interested in it. It sounds like we should go ahead and use serialver to populate this attribute and forget about it. I understand that if our application were managing the persistence of these objects, we would be interested in the version, because we would need to key off it for "upgrading" older persistent objects that are read by a newer version of software. None of that applies in this case, which is the source of confusion here, I'm pretty sure.
    Hope this helps.

  • Lightbox images change direction in mid-presentation

    My lightbox images are changing direction in mid-presentation. They started sliding in horizontally from the right edge of frame. After 4 or 5 are presented, the next images slide in from the left side of frame.

    Is there anything different about that slide or set of slides? Have you tried copying the slides into a new Presentation or opening the Presentation under a different user on your computer?
    What are you using to advance your presentation?

  • How to change the java control panel and the default java in windows.

    Hi,
    Please help on the above problem. I need the answer urgently.
    I have two java version 1.4 and 1.5. I first installed the java version 1.4.2_06 and then 1.5.0_19.Now the default java is 1.5.
    Now I want to chang the java settings to 1.4 by changing the envioronment variable (classpath,path,java_home)
    C:\Program Files\Java\jdk1.5.0_09;C:\j2sdk1.4.2_06
    C:\Program Files\Java\jdk1.5.0_09\lib;C:\j2sdk1.4.2_06\bin
    C:\Program Files\Java\jdk1.5.0_09\bin;C:\j2sdk1.4.2_06\bin
    But after setting these does not solve the problem. The java control panel which appears is the same what was appearing for java 1.5.
    I want to see the control panel for 1.4.2_06.
    Thanks for your help.
    Regards,
    Sarita

    sarita2320 wrote:
    ..Please help on the above problem. I need the answer urgently. ...Is it still urgent?
    When I opened your post and saw that line, I immediately moved it to the 'last in line' of a whole bunch of other stuff I did not have time to look at immediately. Now that all that other stuff that did not bore me with someone else's time constraints is out of the way/taken care of, I've returned to your post.

  • How can I block a site that keeps wanting to change my Java?

    I want to block a site that keeps coming up wanting to change my Java program from "Oracle" Java to something else. Is there a way to block specific sites in Firefox?
    I am running Windows 8.1 on a Toshiba laptop and have Firefox 25.0.1 Mozilla 26-1.0

    hello Nglover1941, you have various adware addons present - maybe one of them is causing the issue. please try these steps:
    # [[Reset Firefox – easily fix most problems|reset firefox]] (this wil keep your bookmarks and passwords)
    # afterwards go to firefox > addons > extensions and in case there are still extensions listed there, disable them.
    # finally run a full scan of your system with different security tools like the [http://www.malwarebytes.org/products/malwarebytes_free free version of malwarebytes] and [http://www.bleepingcomputer.com/download/adwcleaner/ adwcleaner] to make sure that adware isn't present in other places of your system as well.
    [[Troubleshoot Firefox issues caused by malware]]

  • Non-java midi conversion

    I have a bunch of MIDI files that I want to be able to play in my java program. The problem is, I composed them using a program called Midisoft Recording Session, which plays them back with the sound bank provided by my hardware. When I play them in a java program they sound completely different (sometimes just plain awful). I know that I could just have my program play them back with my hardware's sound bank, but then I would lose some cross-platform functionality. Is there a place where I could find a java sound bank that sounds like a typical sound card's bank? Or is there a better solution, like converting to RMF first?? My current solution is to record my MIDIs to WAV format and compress them into u-law or A-law WAV files, but this results in some quality reduction. (CD-quality WAV files are just too big.)

    I've tried the shadow option as some suggest but this trick doesn't seem to work on *captions in Photo Gallery pages*.
    You can not change photos page caption's font style or force text-2-graphic conversion because caption (and most everything else in photos page, albums, blog and podcast page) is rendered by javascript widget.
    I also tried the font mapping option with the plist but my non-standard "fancy" font doesn't show in the list. I tried adding it manually be hand but it still didn't work, perhaps because I'm not referencing the font name correctly. Do I need to add the .ttf or .dfont extension? Does it matter that my fancy font in my home directory font library folder rather than my System font library folder?
    You need to use font name that shows in 'Font Book' for FontMapping.plist to work.
    Font mapping won't work for photos page caption as mention above, but you maybe able to substitute to another font.

  • Changed operating system mid project in Final Cut Pro

    I was working on a  Final Cut project and changed operating systems from Snow leopard to Mavericks in mid project. I have since changed to Mountain Lion as many of my programs were not comparable to run with Mavericks.   My FCP project takes ages to render and auto saves every minute even though I have set it to save less often.  Are these problems the result of changing systems.  I only had a sense this was so after opening an old project and working on it and it running smoothly with fast render etc.
    any help appreciated
    Catherine.

    Do a test. With the range tool make a very short range selection of your project and Share>DVD. In the export dialoge >Settings, choose Hard Drive for Output Device. Click on the Add button for menu background. When the next window appears, hit cancel. See if it exports and burns a disk image, If it does, try the complete project.
    BTW, is your project length 79 minutes or 79 seconds?
    Russ

  • Is there any way to prevent web.xml from any change like java class?

    hi all,
    Is there any way to prevent web.xml from any change after making EAR(WAR)?
    One can easily make a change in web.xml and redeploy the application to get the result. Now we want to restrict the web.xml as java class for any change after making EAR(or WAR).
    Could some one help me to do this?
    thanks,
    dinesh

    hi,
    Not at development level. We want it after deploying the application on server .
    We want to create it (web.xml) at tomcat startup (or in any other web/app server ) before loading any context.
    Is there any way to run a simple java class(not servlet) on tomcat startup(before initializing the contexts)?
    Message was edited by:
    DP_java
    Message was edited by:
    DP_java

  • Sending Program Changes to external MIDI device

    Just getting started with MainStage, so excuse the basic question . . .
    I'd like to use MainStage with two main pieces of hardware – an Elektron Monomachine acting as the master clock and sequencer, and a Machinedrum, which is slaved to the Monomachine. I'm running MainStage to use a soft synth or two sequenced from the Monomachine, and for effects. So far so good.
    Patterns on the Machinedrum are selected externally with MIDI Program Changes. Conversely, when you select patterns on the Monomachine, it sends out a Program Change message so that you can lock the two machines together pattern-wise.
    In Layout mode, I drop in a rotary knob, hit the Learn button and change patterns three times on the Monomachine; the knob says Program Change and the number of the Program (all correct).
    Next, in the Patch editor, I map that screen control to Machinedrum > MIDI Controller > Program Change. If I turn the knob using the mouse, it changes the Program (pattern) on the Machinedrum (all correct).
    BUT . . . now (in either Edit or Perform mode) when I change the pattern on the Monomachine (sending a Program Change message), the knob doesn't move. I see the Program Change message being received by MainStage in the MIDI monitor, but it doesn't get routed to the screen control.
    What could I be doing wrong? Why does it respond correctly in Learn mode, but then not in Edit or Perform mode?

    peterslade wrote:
    BUT . . . now (in either Edit or Perform mode) when I change the pattern on the Monomachine (sending a Program Change message), the knob doesn't move. I see the Program Change message being received by MainStage in the MIDI monitor, but it doesn't get routed to the screen control.
    What could I be doing wrong? Why does it respond correctly in Learn mode, but then not in Edit or Perform mode?
    Hi
    Could it be that MS thinks the incoming PC messages are intended to change MS patches?
    In Edit mode, select the Concert in the Patch list, and change the Program Change Device/channel etc in the Attributes Inspector to something other than the Mono
    HTH
    CCT

  • How do you change default java logo in JOptionPane?

    I want to know how do you change the icon(the java logo in the title bar) for the JOptionPane box. I am using a swing interface. I can change the icon of the main frame but not of the JOptionPane.
    for the main frame i have used:
         Toolkit kit = Toolkit.getDefaultToolkit();
         Image img = kit.getImage("mypicture.gif");
         setIconImage(img);
    Toolkit is part of java.awt package.
    thanks

    here was a discussions about that
    http://forum.java.sun.com/thread.jsp?thread=120724&forum=57&message=316526

Maybe you are looking for

  • Command+1 shortcut doesn't work in iTunes 7?

    During the years of having iTunes 5 & 6, I used to have those keyboard shortcuts like command+1, command+2 to show the main window of iTunes and Equalizer. This function is really helpful when you choose one song to play, then close the iTunes window

  • Does Hyperion Integration Server exist for AS400?

    I need drill through to AS400. I have IBM Data warehouse 7.1 y db2 olap 7.1 on AS400, but sql drill through come with Integration Server.There are any way to install integration server on AS400??

  • DBA_CONSTRAINTS - self join - duplicate rows?

    Hi, I have two tables in 'I' schema. =========== SQL> desc dept; Name Null? Type DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) DEPT.DEPTNO - pk_dept_deptno - PRIMARY KEY SQL> desc emp; Name Null? Type EMPNO NOT NULL NUMBER(4) ENAME VA

  • Ssl-sockets and classloading

    hi, i use rmi using ssl-sockets. the server rebinds to the rmiregistry -> it works fine but when i try to connect from client (browser ie) -> the needed classes (RMISSLCLientSocketFactory...) could not loaded whats the problem?? mike

  • Tm2t. When using High GPU and in secondary landscape, pen and touch react like in landscape

    So I just my tm2t and found this odd problem. When Im using the tablet with the High performance GPU and go to secondary landscape the pen and touch react like the screen is in normal landscape. I switch to Low power GPU and the touch and pen is OK.