本文整理汇总了Java中javax.sound.midi.MetaMessage.getData方法的典型用法代码示例。如果您正苦于以下问题:Java MetaMessage.getData方法的具体用法?Java MetaMessage.getData怎么用?Java MetaMessage.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.midi.MetaMessage
的用法示例。
在下文中一共展示了MetaMessage.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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.");
}
}
}
示例2: 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;
}
示例3: 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];
}
}
示例4: fluidsynthAsyncMIDIevent
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
* Fluidsynth async mid ievent.
*
* @param msg the msg
*/
private void fluidsynthAsyncMIDIevent(MetaMessage msg)
{
byte[] metaData = msg.getData();
String strData = new String(metaData);
//logger.debug("*FS* META message: text= " + strData);
if ("fsbOnLow".equals(strData))
fluidSynth.send(9, ShortMessage.NOTE_ON, 77, 100);
else if ("fsbOnHi".equals(strData))
fluidSynth.send(9, ShortMessage.NOTE_ON, 76, 100);
else if ("fsbOff".equals(strData))
fluidSynth.send(9, ShortMessage.NOTE_OFF, 77, 0);
else if ("fsnOn".equals(strData.substring(0, 5)))
{
lastNote = Integer.parseInt(strData.substring(5));
fluidSynth.send(0, ShortMessage.NOTE_ON, lastNote, 100);
}
else if ("fsnOff".equals(strData.substring(0, 6)))
{
fluidSynth.send(0, ShortMessage.NOTE_OFF, Integer.parseInt(strData.substring(6)), 0);
lastNote = -1;
}
}
示例5: meta
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public void meta(MetaMessage msg) {
System.out.println(""+metaCount+": got "+msg);
if (msg.getType() == 0x2F) {
finished = true;
} else if (msg.getData().length > 0 && msg.getType() == 1) {
metaCount++;
}
}
示例6: addTimeSignatureChange
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
* A {@link TimeSignature} event was detected. Deal with it.
*
* @param event The event.
* @param mm The message from the event.
*/
public void addTimeSignatureChange(MidiEvent event, MetaMessage mm) {
TimeSignature ts = new TimeSignature(mm.getData());
if (!ts.equals(nodes.getLast().getTimeSignature())) {
nodes.add(new TimeTrackerNode(nodes.getLast(), event.getTick(), PPQ));
nodes.getLast().setTimeSignature(ts);
}
}
示例7: addTempoChange
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
* A {@link Tempo} event was detected. Deal with it.
*
* @param event The event.
* @param mm The message from the event.
*/
public void addTempoChange(MidiEvent event, MetaMessage mm) {
Tempo t = new Tempo(mm.getData());
if (!t.equals(nodes.getLast().getTempo())) {
nodes.add(new TimeTrackerNode(nodes.getLast(), event.getTick(), PPQ));
nodes.getLast().setTempo(t);
}
}
示例8: addKeySignatureChange
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
* A {@link KeySignature} event was detected. Deal with it.
*
* @param event The event.
* @param mm The message from the event.
*/
public void addKeySignatureChange(MidiEvent event, MetaMessage mm) {
KeySignature ks = new KeySignature(mm.getData());
if (!ks.equals(nodes.getLast().getKeySignature())) {
nodes.add(new TimeTrackerNode(nodes.getLast(), event.getTick(), PPQ));
nodes.getLast().setKeySignature(ks);
}
}
示例9: decodeMetaMessage
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
private void decodeMetaMessage(MetaMessage message, MusicScore score, double startTime) {
byte[] abMessage = message.getMessage();
byte[] abData = message.getData();
int nDataLength = message.getLength();
switch (message.getType()) {
case MIDIMessageCode.MicrosecondsPerQuarterNote:
int sec = ((abData[0] & 0xFF) << 16) | ((abData[1] & 0xFF) << 8) | (abData[2] & 0xFF);
score.addTempo(new Tempo(startTime, sec));
score.setMicrosecondsPerQuarterNote(sec);
break;
case MIDIMessageCode.SMPTEOffset:
String offset = (abData[0] & 0xFF) + ":" + (abData[1] & 0xFF) + ":" + (abData[2] & 0xFF) + "." + (abData[3] & 0xFF) + "." + (abData[4] & 0xFF);
break;
case MIDIMessageCode.TimeSignature:
int timeSigElement = abData[0] & 0xFF;
int timeSigDenominator = 1 << (abData[1] & 0xFF);
int clocksperMetronome = abData[2] & 0xFF;
int midiClock = abData[3] & 0xFF;
score.setClocksperMetronome(clocksperMetronome);
score.setTimeSigDenominator(timeSigDenominator);
score.setTimeSigElement(timeSigElement);
score.setMidiClock(midiClock);
break;
case MIDIMessageCode.KeySignature:
if (abData[1] == 1) {
score.setGender(false);
} else {
score.setGender(true);
}
score.setKeySignature(abData[0] + 7);
break;
default:
break;
}
}
示例10: KeySignature
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public KeySignature(MetaMessage midiMessage)
{
byte[] data = midiMessage.getData();
if (midiMessage.getType() != META_KEY_SIGNATURE || data.length < 2)
{
throw new IllegalArgumentException("Midi message is not a key signature");
}
this.sharpsFlats = data[0];
this.mode = (data[1] == 1) ? KeyMode.MINOR : KeyMode.MAJOR;
}
示例11: MetaMessageWA
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public MetaMessageWA(MetaMessage rootMessage) throws InvalidMidiDataException {
m_realData = rootMessage.getData();
byte[] newData = new byte[m_realData.length+1];
System.arraycopy(m_realData, 0, newData, 1, m_realData.length);
newData[0] = (byte)rootMessage.getType();
super.setMessage(MidiMessageType.MARKER, newData, newData.length);
}
示例12: decodeMessage
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
private static String decodeMessage(MetaMessage message) {
byte[] abData = message.getData();
String result = null;
switch (message.getType()) {
case 0:
int nSequenceNumber = ((abData[0] & 0xFF) << 8) | (abData[1] & 0xFF);
result = "Sequence Number: " + nSequenceNumber;
break;
case 1:
String strText = new String(abData);
result = "Text Event: " + strText;
break;
case 2:
String strCopyrightText = new String(abData);
result = "Copyright Notice: " + strCopyrightText;
break;
case 3:
String strTrackName = new String(abData);
result = "Sequence/Track Name: " + strTrackName;
break;
case 4:
String strInstrumentName = new String(abData);
result = "Instrument Name: " + strInstrumentName;
break;
case 5:
String strLyrics = new String(abData);
result = "Lyric: " + strLyrics;
break;
case 6:
String strMarkerText = new String(abData);
result = "Marker: " + strMarkerText;
break;
case 7:
String strCuePointText = new String(abData);
result = "Cue Point: " + strCuePointText;
break;
case 0x20:
int nChannelPrefix = abData[0] & 0xFF;
result = "MIDI Channel Prefix: " + nChannelPrefix;
break;
case 0x2F:
result = "End of Track";
break;
case 0x51:
int nTempo = ((abData[0] & 0xFF) << 16) | ((abData[1] & 0xFF) << 8) | (abData[2] & 0xFF); // tempo in microseconds per beat
float bpm = convertTempo(nTempo);
bpm = Math.round(bpm * 100.0f) / 100.0f;
result = "Set Tempo: "+ bpm +" bpm";
break;
case 0x54:
result = "SMTPE Offset: " + (abData[0] & 0xFF) + ":" + (abData[1] & 0xFF) + ":" + (abData[2] & 0xFF) + "." + (abData[3] & 0xFF) + "." + (abData[4] & 0xFF);
break;
case 0x58:
result = "Time Signature: " + (abData[0] & 0xFF) + "/" + (1 << (abData[1] & 0xFF)) + ", MIDI clocks per metronome tick: " +
(abData[2] & 0xFF) + ", 1/32 per 24 MIDI clocks: " + (abData[3] & 0xFF);
break;
case 0x59:
result = "Key Signature: " + KEY_SIGNATURES[abData[0] + 7] + " " + ((abData[1] == 1) ? "minor" : "major");
break;
case 0x7F:
String strDataDump = TextUtilities.toHex(abData);
result = "Sequencer-Specific Meta event: " + strDataDump;
break;
default:
String strUnknownDump = TextUtilities.toHex(abData);
result = "unknown Meta event: " + strUnknownDump;
break;
}
return result;
}
示例13: AssumeResolution
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
/**
* Change resolution (TPQN) without retiming events.
* @param seq Sequence to be processed.
* @param resolution Ticks per quarter note of new sequence.
* @param adjustTempo true if adjust the tempo value to keep the song tempo.
* @return New sequence with new resolution.
* @throws InvalidMidiDataException throw if MIDI data is invalid.
*/
public static Sequence AssumeResolution(Sequence sourceSeq, int resolution, boolean adjustTempo) throws InvalidMidiDataException
{
// sequence must be tick-based
if (sourceSeq.getDivisionType() != Sequence.PPQ)
{
throw new UnsupportedOperationException("SMPTE is not supported.");
}
Sequence seq = new Sequence(sourceSeq.getDivisionType(), resolution);
// process all input tracks
double tempoScale = (double) sourceSeq.getResolution() / seq.getResolution();
for (int trackIndex = 0; trackIndex < sourceSeq.getTracks().length; trackIndex++)
{
Track sourceTrack = sourceSeq.getTracks()[trackIndex];
Track track = seq.createTrack();
// process all events
for (int eventIndex = 0; eventIndex < sourceTrack.size(); eventIndex++)
{
MidiEvent sourceEvent = sourceTrack.get(eventIndex);
MidiEvent event = new MidiEvent(sourceEvent.getMessage(), sourceEvent.getTick());
if (adjustTempo)
{
if (event.getMessage() instanceof MetaMessage)
{
MetaMessage message = (MetaMessage) event.getMessage();
if (message.getType() == MidiUtil.META_TEMPO)
{
byte[] data = message.getData();
if (data.length != 3)
{
throw new InvalidMidiDataException("Illegal tempo event.");
}
int sourceTempo = ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff);
int newTempo = (int) Math.floor(sourceTempo / tempoScale);
data = new byte[] { (byte) ((newTempo >> 16) & 0xff), (byte) ((newTempo >> 8) & 0xff), (byte) (newTempo & 0xff) };
message.setMessage(MidiUtil.META_TEMPO, data, data.length);
}
}
}
track.add(event);
}
}
return seq;
}
示例14: setMessage
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public void setMessage(MetaMessage message)
{
this.type = message.getType();
this.data = message.getData();
}
示例15: parseMicrosecondsPerBeat
import javax.sound.midi.MetaMessage; //导入方法依赖的package包/类
public static final int parseMicrosecondsPerBeat(MetaMessage message, long timestamp)
{
int tempo = message.getData()[0]*16384 + message.getData()[1]*128 + message.getData()[2];
int beatsPerMinute = (int)convertMicrosecondsPerBeatToBPM(tempo);
return beatsPerMinute;
}