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


Java MetaMessage类代码示例

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


MetaMessage类属于javax.sound.midi包,在下文中一共展示了MetaMessage类的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: send

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
@Override
public void send(MidiMessage message, long timeStamp) {
    try {
        if (sound) {
            midiPlugin.sound(message);
        }

        MidiMessageEvent<?> event;
        if (message instanceof ShortMessage) {
            event = MidiUtils.createShortMessageEvent(midiPlugin, (ShortMessage) message, timeStamp);
        } else if (message instanceof SysexMessage) {
            event = new MidiSysexMessageEvent(midiPlugin.getMidiSysexMessageEventName(),
                    midiPlugin.getEngine().getDefaultParameters().getEventClonePolicy(), (SysexMessage) message, timeStamp);
        } else if (message instanceof MetaMessage) {
            event = new MidiMetaMessageEvent(midiPlugin.getMidiMetaMessageEventName(),
                    midiPlugin.getEngine().getDefaultParameters().getEventClonePolicy(), (MetaMessage) message, timeStamp);
        } else {
            throw new SpongeException("Unknown MIDI message type: " + message.getClass());
        }

        midiPlugin.getEngine().getOperations().event(event).send();
    } catch (Exception e) {
        logger.error("send", e);
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:26,代码来源:MidiSpongeEventReceiver.java

示例4: getTempoMPQ

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
/** parses this message for a META tempo message and returns
 * the tempo in MPQ, or -1 if this isn't a tempo message
 */
public static int getTempoMPQ(MidiMessage midiMsg) {
    // first check if it is a META message at all
    if (midiMsg.getLength() != 6
        || midiMsg.getStatus() != MetaMessage.META) {
        return -1;
    }
    byte[] msg = midiMsg.getMessage();
    if (((msg[1] & 0xFF) != META_TEMPO_TYPE) || (msg[2] != 3)) {
        return -1;
    }
    int tempo =    (msg[5] & 0xFF)
                | ((msg[4] & 0xFF) << 8)
                | ((msg[3] & 0xFF) << 16);
    return tempo;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:MidiUtils.java

示例5: checkClone

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
private static void checkClone(MetaMessage msg) throws Exception {
    System.out.print("Original: ");
    byte[] msgData=msg.getData();
    printMsg(msg, msgData);
    MetaMessage msg2=(MetaMessage) msg.clone();
    byte[] msg2Data=msg2.getData();
    System.out.print("Clone:    ");
    printMsg(msg2, msg2Data);

    if (msg2.getLength()!=msg.getLength()
        || msg.getType()!=msg2.getType()
        || msgData.length!=msg2Data.length) {
            throw new Exception("cloned MetaMessage is not equal.");
    }
    int max=Math.min(msgData.length, 10);
    for (int i=0; i<max; i++) {
        if (msgData[i]!=msg2Data[i]) {
            throw new Exception("Cloned MetaMessage data is not equal.");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:MetaMessageClone.java

示例6: 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

示例7: 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

示例8: getMicrosecondsPerQuarterNote

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
/**
 * Gets the number of microseconds per quarter note for a sequence, used to
 * determine its BPM.
 * 
 * @param sequence
 * @return
 */
private static int getMicrosecondsPerQuarterNote(Sequence sequence) {

	// Check all MIDI tracks for MIDI_SET_TEMPO message
	for (Track track : sequence.getTracks()) {
		for (int i = 0; i < track.size(); i++) {
			MidiEvent event = track.get(i);
			MidiMessage message = event.getMessage();
			if (message instanceof MetaMessage) {
				MetaMessage m = (MetaMessage) message;
				byte[] data = m.getData();
				int type = m.getType();
				if (type == MIDI_SET_TEMPO) {
					return ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff);
				}
			}
		}
	}
	return 0;
}
 
开发者ID:TaylorPeer,项目名称:AI-909,代码行数:27,代码来源:MidiUtilities.java

示例9: meta

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
@Override
public void meta(MetaMessage event) {
   	// we are only worried about the end of track meta message
       if (event.getType() == MidiAudioPlayer.END_OF_TRACK_MESSAGE) {
       	// make sure the audio should loop
           if (this.configuration.isLoopEnabled()) {
           	this.loop();
           	// log that the audio is being looped
   	        LOGGER.debug("Looping");
           } else {
           	this.stop();
           }
       	// set the volume again
       	this.setVolume(this.configuration.getVolume());
   		// set the mute control
   		this.setMuted(this.configuration.isAudioMuted());
       }
}
 
开发者ID:wnbittle,项目名称:praisenter,代码行数:19,代码来源:MidiAudioPlayer.java

示例10: findFirstTempo

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
/**
 * Find the first tempo meta message and return the tempo value
 * @return
 */
public static float findFirstTempo(Sequence sequence) throws Exception
{
		for(Track track : sequence.getTracks())
		{
			for(int n=0;n<track.size();n++)
			{
				MidiEvent event = track.get(n);

				if(event.getMessage() instanceof MetaMessage
						&& ((MetaMessage)event.getMessage()).getType()==0x51)
				{
					float tempo = new TempoMessage((MetaMessage)event.getMessage()).getBpm();
					System.out.println("Found tempomessage "+tempo+" bpm");
					return tempo;
				}
			}
		}
		throw new Exception("No tempo message found");
}
 
开发者ID:petersalomonsen,项目名称:frinika,代码行数:24,代码来源:MidiSequenceConverter.java

示例11: 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

示例12: TimeSignature

import javax.sound.midi.MetaMessage; //导入依赖的package包/类
public TimeSignature(MetaMessage midiMessage)
{
	byte[] data = midiMessage.getData();
	if (midiMessage.getType() != META_TIME_SIGNATURE || data.length < 4)
	{
		throw new IllegalArgumentException("Midi message is not a time signature event");
	}

	if ((1 << data[1]) > MAX_DENOMINATOR)
	{
		this.numerator = 4;
		this.denominator = 4;
		this.metronome = 24;
		this.thirtySecondNotes = 8;
	}
	else
	{
		this.numerator = data[0];
		this.denominator = 1 << data[1];
		this.metronome = data[2];
		this.thirtySecondNotes = data[3];
	}
}
 
开发者ID:digero,项目名称:maestro,代码行数:24,代码来源:TimeSignature.java

示例13: 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

示例14: 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

示例15: 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


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