当前位置: 首页>>代码示例>>Java>>正文


Java MetaMessage.setMessage方法代码示例

本文整理汇总了Java中javax.sound.midi.MetaMessage.setMessage方法的典型用法代码示例。如果您正苦于以下问题:Java MetaMessage.setMessage方法的具体用法?Java MetaMessage.setMessage怎么用?Java MetaMessage.setMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.sound.midi.MetaMessage的用法示例。


在下文中一共展示了MetaMessage.setMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeTempo

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
 * Write the given tempo out to {@link #sequence} at the given tick.
 * 
 * @param tempo The tempo to write.
 * @param tick The tick at which to write it.
 * 
 * @throws InvalidMidiDataException If the tempo contained invalid Midi data.
 */
private void writeTempo(Tempo tempo, long tick) throws InvalidMidiDataException {
	MetaMessage mm = new MetaMessage();
	
	int mspq = tempo.getMicroSecondsPerQuarter();
	
	byte[] data = {
			(byte) ((mspq & 0xff000000) >> 24),
			(byte) ((mspq & 0x00ff0000) >> 16),
			(byte) ((mspq & 0x0000ff00) >> 8),
			(byte) (mspq & 0x000000ff)};
	
	// Clear leading 0's
	int i;
	for (i = 0; i < data.length - 1 && data[i] == 0; i++);
	if (i != 0) {
		data = Arrays.copyOfRange(data, i, data.length);
	}
	
	mm.setMessage(EventParser.TEMPO, data, data.length);
	
	sequence.getTracks()[0].add(new MidiEvent(mm, tick));
}
 
开发者ID:apmcleod,项目名称:voice-splitting,代码行数:31,代码来源:MidiWriter.java

示例2: setUp

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
protected void setUp() throws Exception {
       super.setUp();	
       seq = new Sequence(Sequence.PPQ, resolution,1);
	

	
	int mpq = (int)(60000000 / tempo);
	try
	{
		MetaMessage tempoMsg = new MetaMessage();
		tempoMsg.setMessage(0x51,new byte[] {
			(byte)(mpq>>16 & 0xff),
			(byte)(mpq>>8 & 0xff),
			(byte)(mpq & 0xff)
		},3);
		MidiEvent tempoEvent = new MidiEvent(tempoMsg,0);
           seq.getTracks()[0].add(tempoEvent);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:petersalomonsen,项目名称:frinika,代码行数:22,代码来源:TempoAfterImportSaveLoadTest.java

示例3: main

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // let's create some MetaMessages and check them
    MetaMessage msg=new MetaMessage();
    String text="a textmarker";
    msg.setMessage(1, text.getBytes(), text.length());
    checkClone(msg);
    msg.setMessage(0x2E, new byte[0], 0);
    checkClone(msg);
    byte[] data=new byte[17000];
    for (int i=0; i<30; data[i]=(byte) (i++ & 0xFF));
    msg.setMessage(0x02, data, 80); checkClone(msg);
    msg.setMessage(0x02, data, 160); checkClone(msg);
    msg.setMessage(0x02, data, 400); checkClone(msg);
    msg.setMessage(0x02, data, 1000); checkClone(msg);
    msg.setMessage(0x02, data, 10000); checkClone(msg);
    msg.setMessage(0x02, data, 17000); checkClone(msg);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:MetaMessageClone.java

示例4: writeTimeSignature

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
 * Write the given time signature out to {@link #sequence} at the given tick.
 * 
 * @param timeSignature The time signature to write.
 * @param tick The tick at which to write it.
 * @throws InvalidMidiDataException If the time signature contained invalid Midi data.
 */
private void writeTimeSignature(TimeSignature timeSignature, long tick) throws InvalidMidiDataException {
	MetaMessage mm = new MetaMessage();
	
	int denominator = timeSignature.getDenominator();
	
	// Base 2 log calculator for whole numbers
	int i = 0;
	while (denominator != 1) {
		denominator /= 2;
		i++;
	}
	
	byte[] data = {
			(byte) timeSignature.getNumerator(),
			(byte) i,
			(byte) timeSignature.getMetronomeTicksPerBeat(),
			(byte) timeSignature.getNotes32PerQuarter()};
	
	mm.setMessage(EventParser.TIME_SIGNATURE, data, data.length);
	
	sequence.getTracks()[0].add(new MidiEvent(mm, tick));
}
 
开发者ID:apmcleod,项目名称:voice-splitting,代码行数:30,代码来源:MidiWriter.java

示例5: getSequence

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/** Create a sequence from an InputStream.
 *  This is the counterpart of {@link MidiSystem#getSequence(InputStream)}
 *  for MUS format.
 *
 * @param is MUS data (this method does not try to auto-detect the format.)
 */
public static Sequence getSequence(InputStream is)
throws IOException, InvalidMidiDataException {
    DataInputStream dis = new DataInputStream(is);
    dis.skip(6);
    int rus = dis.readUnsignedShort();
    short scoreStart = Swap.SHORT((char) rus);
    dis.skip(scoreStart - 8);
    Sequence sequence = new Sequence(Sequence.SMPTE_30, 14, 1);
    Track track = sequence.getTracks()[0];
    int[] chanVelocity = new int[16];
    Arrays.fill(chanVelocity, 100);
    EventGroup eg;
    long tick = 0;
    while ((eg = nextEventGroup(dis, chanVelocity)) != null) {
        tick = eg.appendTo(track, tick);
    }
    MetaMessage endOfSequence = new MetaMessage();
    endOfSequence.setMessage(47, new byte[] {0}, 1);
    track.add(new MidiEvent(endOfSequence, tick));
    return sequence;
}
 
开发者ID:AXDOOMER,项目名称:mochadoom,代码行数:28,代码来源:MusReader.java

示例6: toMidiMessage

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public MetaMessage toMidiMessage()
{
	MetaMessage midiMessage = new MetaMessage();
	byte[] data = new byte[4];
	data[0] = (byte) numerator;
	data[1] = floorLog2(denominator);
	data[2] = metronome;
	data[3] = thirtySecondNotes;

	try
	{
		midiMessage.setMessage(META_TIME_SIGNATURE, data, data.length);
	}
	catch (InvalidMidiDataException e)
	{
		throw new RuntimeException(e);
	}
	return midiMessage;
}
 
开发者ID:digero,项目名称:maestro,代码行数:20,代码来源:TimeSignature.java

示例7: createTempoEvent

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
 * @param mpqn Microseconds per quarter note
 */
public static MidiEvent createTempoEvent(int mpqn, long ticks)
{
	try
	{
		byte[] data = new byte[3];
		data[0] = (byte) ((mpqn >>> 16) & 0xFF);
		data[1] = (byte) ((mpqn >>> 8) & 0xFF);
		data[2] = (byte) (mpqn & 0xFF);

		MetaMessage msg = new MetaMessage();
		msg.setMessage(META_TEMPO, data, data.length);
		return new MidiEvent(msg, ticks);
	}
	catch (InvalidMidiDataException e)
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:digero,项目名称:maestro,代码行数:22,代码来源:MidiFactory.java

示例8: toMidiMessage

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public MetaMessage toMidiMessage()
{
	try
	{
		MetaMessage midiMessage = new MetaMessage();
		byte[] data = new byte[2];
		data[0] = sharpsFlats;
		data[1] = (byte) (mode == KeyMode.MINOR ? 1 : 0);
		midiMessage.setMessage(META_KEY_SIGNATURE, data, data.length);
		return midiMessage;
	}
	catch (InvalidMidiDataException e)
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:digero,项目名称:maestro,代码行数:17,代码来源:KeySignature.java

示例9: test_getType

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
 * Test method getType() of class MetaMessage
 * 
 */
public void test_getType() throws Exception {
    MetaMessage meta = new MetaMessage();
    assertEquals(0, meta.getType());

    byte[] bt = new byte[] { 9, -4, 34, 18 };
    MetaMessage1 meta2 = new MetaMessage1(bt);
    assertEquals(252, meta2.getType());
    bt[1] = 5;
    /**
     * value change
     */
    assertEquals(5, meta2.getType());
    
    meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
    assertEquals(10, meta.getType());

    meta.setMessage(27, null, 0);
    assertEquals(27, meta.getType());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:24,代码来源:MetaMessageTest.java

示例10: test_getType

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
 * Test method getType() of class MetaMessage
 * 
 */
public void test_getType() throws Exception {
    MetaMessage meta = new MetaMessage();
    assertEquals(meta.getType(), 0);

    byte[] bt = new byte[] { 9, -4, 34, 18 };
    MetaMessage1 meta2 = new MetaMessage1(bt);
    assertEquals(meta2.getType(), 252);
    bt[1] = 5;
    /**
     * value change
     */
    assertEquals(5, meta2.getType());
    
    meta.setMessage(10, new byte[] { 1, 2, 3, 4 }, 4);
    assertEquals(meta.getType(), 10);

    meta.setMessage(27, null, 0);
    assertEquals(meta.getType(), 27);
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:24,代码来源:MetaMessageTest.java

示例11: getTempoMessage

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/** Creates a MIDI tempo change event if this Sound element specifies tempo.
 * @return a MetaMessage or null, if no tempo attribute was found
 */
public MetaMessage getTempoMessage() {
  if (element.hasAttribute("tempo")) {
    final float tempo = Float.parseFloat(element.getAttribute("tempo"));
    int midiTempo = Math.round((float)60000.0 / tempo * 1000);
    final MetaMessage message = new MetaMessage();
    byte[] bytes = new byte[3];
    bytes[0] = (byte) (midiTempo / 0X10000);
    midiTempo %= 0X10000;
    bytes[1] = (byte) (midiTempo / 0X100);
    midiTempo %= 0X100;
    bytes[2] = (byte) midiTempo;
    try {
      message.setMessage(0X51, bytes, bytes.length);
      return message;
    } catch (InvalidMidiDataException e) {}
  }
  return null;
}
 
开发者ID:mlang,项目名称:freedots,代码行数:22,代码来源:Sound.java

示例12: MetaCallback

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
MetaCallback() throws Exception {

        sequencer=MidiSystem.getSequencer();
        sequence=new Sequence(Sequence.PPQ,240);
        track=sequence.createTrack();
        sequencer.addMetaEventListener(this);

        byte[] data = new byte[1];

        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,100),0));
        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,0),0 + 240));
        int c;
        for(c=0; c < TOTAL_COUNT; c++) {
            data[0]=(byte)(c+1);
            MetaMessage meta = new MetaMessage();
            meta.setMessage(1, data, 1); // type, data, length
            track.add(new MidiEvent(meta,c*20));
        }
        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),c*20));
        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),c*20 + 10));

        sequencer.setSlaveSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
        sequencer.setMasterSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
        sequencer.open();
        sequencer.setSequence(sequence);
        sequencer.setTempoInBPM(100);
        System.out.println("Starting playback...");
        this.start();
        while (!finished && sequencer.getTickPosition() < sequencer.getTickLength()) {
            System.out.println("Tick "+sequencer.getTickPosition()+"...");
            Thread.sleep(1000);
        }
        System.out.println("Stopping playback...");
        this.stop();
        if (metaCount != TOTAL_COUNT) {
            throw new Exception("Expected "+TOTAL_COUNT+" callbacks, but got "+metaCount+"!");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:MetaCallback.java

示例13: tempoInUSQ

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public static MidiMessage tempoInUSQ(int usq){
	try {
		MetaMessage message = new MetaMessage();
		message.setMessage(0x51, new byte[]{ (byte)((usq >> 16) & 0x00FF),(byte)((usq >> 8) & 0x00FF),(byte)((usq) & 0x00FF) }, 3);
		return message;
	} catch (InvalidMidiDataException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:11,代码来源:MidiMessageUtils.java

示例14: timeSignature

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public static MidiMessage timeSignature(TGTimeSignature ts){
	try {
		MetaMessage message = new MetaMessage();
		message.setMessage(0x58, new byte[]{  (byte)ts.getNumerator(),(byte)ts.getDenominator().getIndex(),(byte)(96 / ts.getDenominator().getValue()),8 }, 4);
		return message;
	} catch (InvalidMidiDataException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:11,代码来源:MidiMessageUtils.java

示例15: writeKeySignature

import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
 * Write the given key signature out to {@link #sequence} at the given tick.
 * 
 * @param keySignature The key signature to write.
 * @param tick The tick at which to write it.
 * @throws InvalidMidiDataException If the key signature produces invalid Midi data.
 */
private void writeKeySignature(KeySignature keySignature, long tick) throws InvalidMidiDataException {
	MetaMessage mm = new MetaMessage();
	
	byte[] data = {
			(byte) keySignature.getNumSharps(),
			(byte) (keySignature.isMajor() ? 0 : 1)};
	
	mm.setMessage(EventParser.KEY_SIGNATURE, data, data.length);
	
	sequence.getTracks()[0].add(new MidiEvent(mm, tick));
}
 
开发者ID:apmcleod,项目名称:voice-splitting,代码行数:19,代码来源:MidiWriter.java


注:本文中的javax.sound.midi.MetaMessage.setMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。