本文整理汇总了Java中com.leff.midi.event.NoteOn类的典型用法代码示例。如果您正苦于以下问题:Java NoteOn类的具体用法?Java NoteOn怎么用?Java NoteOn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NoteOn类属于com.leff.midi.event包,在下文中一共展示了NoteOn类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeMidi
import com.leff.midi.event.NoteOn; //导入依赖的package包/类
public static File makeMidi(Context context, int[]chord){
MidiTrack tempo = new MidiTrack();
int c = 0;
int v = 100;
ArrayList<MidiTrack> midiTracks = new ArrayList<>();
//MAKE TEMPO
TimeSignature ts = new TimeSignature();
ts.setTimeSignature(4, 4, TimeSignature.DEFAULT_METER, TimeSignature.DEFAULT_DIVISION);
Tempo t = new Tempo();
t.setBpm(120);
tempo.insertEvent(ts);
tempo.insertEvent(t);
midiTracks.add(tempo);
//ADD OTHER TRACKS
for(int i=0; i<chord.length;i++){
MidiTrack midiTrack = new MidiTrack();
NoteOn noteOn= new NoteOn(480,c,60+chord[i],v);
NoteOff noteOff = new NoteOff(480 + 480*3, c,60+chord[i],0);
midiTrack.insertEvent(noteOn);
midiTrack.insertEvent(noteOff);
midiTracks.add(midiTrack);
}
MidiFile midi = new MidiFile(MidiFile.DEFAULT_RESOLUTION, midiTracks);
File output = new File(context.getFilesDir()+"m.mid");
try
{
midi.writeToFile(output);
}
catch(IOException e)
{
System.err.println(e);
}
return output;
}
示例2: makeMidiFile
import com.leff.midi.event.NoteOn; //导入依赖的package包/类
public static File makeMidiFile(Context context, int[]chord,String name){
MidiTrack tempo = new MidiTrack();
int c = 0;
int v = 80;
ArrayList<MidiTrack> midiTracks = new ArrayList<>();
//MAKE TEMPO
TimeSignature ts = new TimeSignature();
ts.setTimeSignature(4, 4, TimeSignature.DEFAULT_METER, TimeSignature.DEFAULT_DIVISION);
Tempo t = new Tempo();
t.setBpm(120);
tempo.insertEvent(ts);
tempo.insertEvent(t);
midiTracks.add(tempo);
//ADD OTHER TRACKS
for(int i=0; i<chord.length;i++){
MidiTrack midiTrack = new MidiTrack();
NoteOn noteOn= new NoteOn(480,c,60+chord[i],v);
NoteOff noteOff = new NoteOff(480+ 300,c,60+chord[i],0);
midiTrack.insertEvent(noteOn);
midiTrack.insertEvent(noteOff);
midiTracks.add(midiTrack);
}
MidiFile midi = new MidiFile(MidiFile.DEFAULT_RESOLUTION, midiTracks);
File output = new File(context.getFilesDir()+name);
try
{
midi.writeToFile(output);
}
catch(IOException e)
{
System.err.println(e);
}
return output;
}
示例3: main
import com.leff.midi.event.NoteOn; //导入依赖的package包/类
public static void main(String[] args)
{
// 1. Create some MidiTracks
MidiTrack tempoTrack = new MidiTrack();
MidiTrack noteTrack = new MidiTrack();
// 2. Add events to the tracks
// 2a. Track 0 is typically the tempo map
TimeSignature ts = new TimeSignature();
ts.setTimeSignature(4, 4, TimeSignature.DEFAULT_METER, TimeSignature.DEFAULT_DIVISION);
Tempo t = new Tempo();
t.setBpm(228);
tempoTrack.insertEvent(ts);
tempoTrack.insertEvent(t);
// 2b. Track 1 will have some notes in it
for(int i = 0; i < 80; i++)
{
int channel = 0, pitch = 1 + i, velocity = 100;
NoteOn on = new NoteOn(i * 480, channel, pitch, velocity);
NoteOff off = new NoteOff(i * 480 + 120, channel, pitch, 0);
noteTrack.insertEvent(on);
noteTrack.insertEvent(off);
// There is also a utility function for notes that you should use
// instead of the above.
noteTrack.insertNote(channel, pitch + 2, velocity, i * 480, 120);
}
// It's best not to manually insert EndOfTrack events; MidiTrack will
// call closeTrack() on itself before writing itself to a file
// 3. Create a MidiFile with the tracks we created
ArrayList<MidiTrack> tracks = new ArrayList<MidiTrack>();
tracks.add(tempoTrack);
tracks.add(noteTrack);
MidiFile midi = new MidiFile(MidiFile.DEFAULT_RESOLUTION, tracks);
// 4. Write the MIDI data to a file
File output = new File("exampleout.mid");
try
{
midi.writeToFile(output);
}
catch(IOException e)
{
System.err.println(e);
}
}
示例4: main
import com.leff.midi.event.NoteOn; //导入依赖的package包/类
public static void main(String[] args) {
// 1. Create some MidiTracks
MidiTrack tempoTrack = new MidiTrack();
MidiTrack noteTrack = new MidiTrack();
// 2. Add events to the tracks
// 2a. Track 0 is typically the tempo map
TimeSignature ts = new TimeSignature();
ts.setTimeSignature(4, 4, TimeSignature.DEFAULT_METER, TimeSignature.DEFAULT_DIVISION);
Tempo t = new Tempo();
t.setBpm(228);
tempoTrack.insertEvent(ts);
tempoTrack.insertEvent(t);
// 2b. Track 1 will have some notes in it
for (int i = 0; i < 80; i++) {
int channel = 0, pitch = 1 + i, velocity = 100;
NoteOn on = new NoteOn(i * 480, channel, pitch, velocity);
NoteOff off = new NoteOff(i * 480 + 120, channel, pitch, 0);
noteTrack.insertEvent(on);
noteTrack.insertEvent(off);
// There is also a utility function for notes that you should use
// instead of the above.
noteTrack.insertNote(channel, pitch + 2, velocity, i * 480, 120);
}
// It's best not to manually insert EndOfTrack events; MidiTrack will
// call closeTrack() on itself before writing itself to a file
// 3. Create a MidiFile with the tracks we created
ArrayList<MidiTrack> tracks = new ArrayList<MidiTrack>();
tracks.add(tempoTrack);
tracks.add(noteTrack);
MidiFile midi = new MidiFile(MidiFile.DEFAULT_RESOLUTION, tracks);
// 4. Write the MIDI data to a file
File output = new File("exampleout.mid");
try {
midi.writeToFile(output);
} catch (IOException e) {
System.err.println(e);
}
}
示例5: insertNote
import com.leff.midi.event.NoteOn; //导入依赖的package包/类
public void insertNote(int channel, int pitch, int velocity, long tick, long duration) {
insertEvent(new NoteOn(tick, channel, pitch, velocity));
insertEvent(new NoteOn(tick + duration, channel, pitch, 0));
}
示例6: insertNote
import com.leff.midi.event.NoteOn; //导入依赖的package包/类
public void insertNote(int channel, int pitch, int velocity, long tick, long duration)
{
insertEvent(new NoteOn(tick, channel, pitch, velocity));
insertEvent(new NoteOn(tick + duration, channel, pitch, 0));
}