| |

VerySource

 Forgot password?
 Register
Search
View: 1165|Reply: 5

How to generate midi files in java? Urgently ask the master to answer! ! !

[Copy link]

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2021-3-3 12:30:01
| Show all posts |Read mode
For our multimedia final assignment, I chose a midi project, asked for information about the midi file, and then generated a midi file. . .

I found more information. . It seems that there is no programming to generate midi files. . I fainted. . I personally only have a foundation in java. No other programming language will. . . Hope that the expert will give you advice. How to generate midi files with java programming? ? I have seen the api of java sound midi. . But it still won't work. I don't know if there is a way to generate midi. .
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2021-3-3 13:00:01
| Show all posts
No. . Ugh. . It seems not easy to generate this. .

correct. I came down to a piano program that is said to be written by Sun company, which can generate, save and play midi files. I am studying the source code. .
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2021-3-3 13:15:01
| Show all posts
Use the jfugue package, which can be downloaded online
Reply

Use magic Report

1

Threads

51

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2021-3-3 13:30:01
| Show all posts
Piano program? -.-
Reply

Use magic Report

1

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2021-3-3 13:45:01
| Show all posts
try this one:

import javax.sound.midi.*;

class Test
{
    public static void main(String[] args)
    {
        try
        {
            Sequencer sequencer = MidiSystem.getSequencer();
            sequencer.open();

            Sequence seq = new Sequence(Sequence.PPQ, 4);
            Track track = seq.createTrack();

            for (int i = 5; i <61; i++)
            {
                track.add(makeEvent(144, 1, i, 100, i));
                track.add(makeEvent(128, 1, i, 100, i + 2));
            } // end loop

            sequencer.setSequence(seq);
            sequencer.setTempoInBPM(220);
            sequencer.start();

            quitProgram(sequencer);


        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    } // end main

    public static void quitProgram(Sequencer sequencer)
    {
        while(sequencer.isRunning())
        {
            System.out.println("isRunning");
        }

        System.exit(0);
    }

    public static MidiEvent makeEvent(int comd, int chan, int one, int two,
                                      int tick)
    {
        MidiEvent event = null;
        try
        {
            ShortMessage a = new ShortMessage();
            a.setMessage(comd, chan, one, two);
            event = new MidiEvent(a, tick);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return event;
    }

}
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2021-3-3 14:00:01
| Show all posts
thanks for your help, but I have finished it. :),my teacher gave me some code.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list