本文整理汇总了Java中javax.sound.midi.ShortMessage.NOTE_ON属性的典型用法代码示例。如果您正苦于以下问题:Java ShortMessage.NOTE_ON属性的具体用法?Java ShortMessage.NOTE_ON怎么用?Java ShortMessage.NOTE_ON使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.sound.midi.ShortMessage
的用法示例。
在下文中一共展示了ShortMessage.NOTE_ON属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMessage
private void parseMessage(MidiMessage message) throws MidiPlayerException{
byte[] data = message.getMessage();
if( data.length > 0 ){
//NOTE ON
if(((data[0] & 0xFF) & 0xF0) == ShortMessage.NOTE_ON){
parseNoteOn(data, findChannel(message), findVoice(message), findBendMode(message));
}
//NOTE OFF
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.NOTE_OFF){
parseNoteOff(data, findChannel(message), findVoice(message), findBendMode(message));
}
//PITCH BEND
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.PITCH_BEND){
parsePitchBend(data, findChannel(message), findVoice(message), findBendMode(message));
}
//PROGRAM CHANGE
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.PROGRAM_CHANGE){
parseProgramChange(data, findChannel(message));
}
//CONTROL CHANGE
else if(((data[0] & 0xFF) & 0xF0) == ShortMessage.CONTROL_CHANGE){
parseControlChange(data, findChannel(message));
}
}
}
示例2: send
public void send(MidiMessage inMessage, long inTimeStamp)
{
if(inMessage instanceof ShortMessage)
{
ShortMessage mm = (ShortMessage)inMessage;
switch(mm.getCommand())
{
case ShortMessage.NOTE_ON:
case ShortMessage.NOTE_OFF:
MiProvider.instance().noteReceived(mm, inTimeStamp);
break;
case ShortMessage.CONTROL_CHANGE:
//System.err.println("Control change");
break;
}
}
}
示例3: render
@Override
public void render() throws RenderCommandException {
sleepUntil(getFrame().playOutTime);
for(MidiMessage msg : getFrame().messages) {
if(msg instanceof ShortMessage) {
final ShortMessage sm = (ShortMessage)msg;
final MidiChannel ch = synth.getChannels()[sm.getChannel()];
switch(sm.getCommand()) {
case ShortMessage.NOTE_ON:
ch.noteOn(sm.getData1(), sm.getData2());
continue;
case ShortMessage.NOTE_OFF:
ch.noteOff(sm.getData1(), sm.getData2());
continue;
case ShortMessage.PROGRAM_CHANGE:
ch.programChange(sm.getData1());
continue;
case ShortMessage.CONTROL_CHANGE:
ch.controlChange(sm.getData1(), sm.getData2());
continue;
}
}
throw new RenderCommandException("Unknown MIDI Command:" + MidiToString.toString(msg));
}
}
示例4: handle
@Override
public void handle(MidiMessage msg) {
if(msg instanceof ShortMessage) {
ShortMessage smsg = (ShortMessage)msg;
switch(smsg.getCommand()) {
case ShortMessage.CONTROL_CHANGE:
int cc = smsg.getData1();
if(cc2run[cc] != null) cc2run[cc].handle(msg);
break;
case ShortMessage.NOTE_ON:
int key = smsg.getData1();
if(key2run[key] != null) key2run[key].handle(msg);
break;
case ShortMessage.PITCH_BEND:
pitchBend.set(smsg);
synchronized (processMidi) {processMidi.notifyAll();}
break;
}
}
System.out.println(MidiToString.toString(msg));
}
示例5: isRunningStatusMessage
/**
* Checks whether a status byte represents a running-status message, which means that multiple messages can be
* sent without re-sending the status byte, for example to support multiple note-on messages in a row by simply
* sending a stream of data byte pairs after the note-on status byte.
*
* @param status the status byte which is being processed.
*
* @return true if we should stay in this status after receiving our full complement of data bytes.
*/
private boolean isRunningStatusMessage (int status) {
switch( status & 0xF0 ) {
case ShortMessage.NOTE_OFF:
case ShortMessage.NOTE_ON:
case ShortMessage.POLY_PRESSURE:
case ShortMessage.CONTROL_CHANGE:
case ShortMessage.PROGRAM_CHANGE:
case ShortMessage.CHANNEL_PRESSURE:
case ShortMessage.PITCH_BEND:
return true;
default:
return false;
}
}
示例6: isValid
public boolean isValid(MultiEvent ev) {
switch(cmd) {
case ShortMessage.NOTE_ON:
return (ev instanceof NoteEvent) ;
case ShortMessage.CONTROL_CHANGE:
if (!(ev instanceof ControllerEvent)) return false;
ControllerEvent ce=(ControllerEvent)ev;
return contrl == ce.getControlNumber();
case ShortMessage.PITCH_BEND:
return (ev instanceof PitchBendEvent) ;
default:
try {
throw new Exception(" unknown event type " + ev);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
示例7: send
@Override public void send(MidiMessage message, long timeStamp)
{
if (receiver == null)
return;
if (hasAbcPart && message instanceof ShortMessage)
{
ShortMessage m = (ShortMessage) message;
int c = m.getChannel();
int cmd = m.getCommand();
int noteId = m.getData1();
int speed = m.getData2();
boolean noteOnMsg = (cmd == ShortMessage.NOTE_ON) && speed > 0;
boolean noteOffMsg = (cmd == ShortMessage.NOTE_OFF) || (cmd == ShortMessage.NOTE_ON && speed == 0);
if (!isNoteActive(noteId) && !(isNoteOn(c, noteId) && noteOffMsg))
return;
if (noteOnMsg)
setNoteOn(c, noteId, true);
else if (noteOffMsg)
setNoteOn(c, noteId, false);
}
receiver.send(message, timeStamp);
}
示例8: send
public void send(MidiMessage message, long timeStamp)
throws IllegalStateException
{
if (message instanceof ShortMessage)
{
ShortMessage smessage = (ShortMessage) message;
switch (message.getStatus())
{
case ShortMessage.NOTE_ON:
int velocity = smessage.getData2();
if (velocity > 0)
channels[smessage.getChannel()].noteOn(smessage.getData1(),
smessage.getData2());
else
channels[smessage.getChannel()].noteOff(smessage.getData1());
break;
case ShortMessage.CONTROL_CHANGE:
channels[smessage.getChannel()].controlChange(smessage.getData1(),
smessage.getData2());
break;
default:
System.out.println ("Unhandled message: " + message.getStatus());
break;
}
}
}
示例9: noteOn
private MidiEvent noteOn(int key, int velocity, long ticks) {
try {
return new MidiEvent(new ShortMessage(ShortMessage.NOTE_ON, 0, key, velocity), ticks);
} catch(InvalidMidiDataException e) {
return null;
}
}
示例10: send
public void send(MidiMessage message, long timeStamp)
throws IllegalStateException
{
if (message instanceof ShortMessage)
{
ShortMessage smessage = (ShortMessage) message;
switch (message.getStatus())
{
case ShortMessage.NOTE_ON:
int velocity = smessage.getData2();
if (velocity > 0)
channels[smessage.getChannel()].noteOn(smessage.getData1(),
smessage.getData2());
else
channels[smessage.getChannel()].noteOff(smessage.getData1());
break;
case ShortMessage.CONTROL_CHANGE:
channels[smessage.getChannel()].controlChange(smessage.getData1(),
smessage.getData2());
break;
default:
System.out.println ("Unhandled message: " + message.getStatus());
break;
}
}
}
示例11: midiMessage
public void midiMessage(MidiMessage message) {
if (!(message instanceof ShortMessage)) return;
if (message.getStatus() == ShortMessage.NOTE_ON) {
float val=(float) ((((ShortMessage)message).getData1())/127.0);
if (val > monitVal) monitVal=val;
}
}
示例12: setSequence
public void setSequence(Sequence sequence) {
this.sequence = sequence;
// calculate length in beats and notes count
Track track = getTrack();
notesCount = 0;
long start = -1;
long end = -1;
int size = track.size();
if (size > 0) {
for (int i = 0; i < size; i++) {
MidiEvent ev = track.get(i);
MidiMessage msg = ev.getMessage();
if ((msg instanceof ShortMessage) && (((ShortMessage)msg).getCommand() == ShortMessage.NOTE_ON)) {
notesCount++;
if (start == -1) {
start = ev.getTick();
}
end = ev.getTick();
}
}
int resolution = sequence.getResolution();
long b1 = (start + (resolution/4)) / resolution; // +res/2: allow notes to start a bit earlier but still be counted to other bar
long b2 = (end - (resolution/4)) / resolution; // - res/2: ...
lengthInBeats = (int)(b2 - b1 + 1);
length = lengthInBeats * resolution;
} else {
length = 0;
}
}
示例13: findNearest
private long findNearest(long tick, int[] v) {
if (notesCount == 0) return tick;
Track track = getTrack();
int size = track.size();
int shift = 4 * sequence.getResolution(); // pattern starts at 4 * ppq
long t = tick % length; // tick inside pattern, to be (de-)quantized
t = tick + shift;
int i = 0;
long nearest = -1;
v[0] = 100;
long tt = t;
MidiEvent ev;
boolean isNote;
do {
ev = track.get(i++);
tt = ev.getTick();
MidiMessage msg = ev.getMessage();
isNote = (msg instanceof ShortMessage) && (((ShortMessage)msg).getCommand() == ShortMessage.NOTE_ON);
if ((isNote) && ( ( tt < t ) || ( (tt-t) < (t-nearest) ) ) ) {
nearest = tt;
v[0] = ((ShortMessage)msg).getData2();
}
} while ((i < size) && ((!isNote) || (tt < t))); // stops after first note imediately following after (tt<t) no longer is true
return nearest - shift;
}
示例14: messageReceived
@Override
protected void messageReceived(Bead message) {
if (Midi.hasMidiMessage(message)) {
MidiMessage msg = Midi.getMidiMessage(message);
if (msg instanceof ShortMessage) {
// Note that NOTE_OFF messages are ignored.
// NOTE_ON messages trigger the appropriate sample to be played.
if (msg.getStatus() == ShortMessage.NOTE_ON) {
//System.out.println("Sample note on?");
// Find the appropriate SamplePlayer
int note = ((ShortMessage)msg).getData1();
final PlayerInfo sp = samplePlayers.get(note);
if (sp != null) {
// double time = ac.getTime();
// System.out.printf("Play sample %d at %f from %f..%f ms\n", note, time, sp.range.startMs, sp.range.endMs);
sp.player.reset();
sp.player.setPosition(sp.range.startMs);
float durationMs = (float)(sp.range.endMs - sp.range.startMs);
sp.env.clear();
float middleTimeMs = durationMs - 2*RAMP_TIME_MS;
sp.env.addSegment(1.0f, RAMP_TIME_MS);
if (middleTimeMs > 0) {
sp.env.addSegment(1.0f, middleTimeMs);
}
sp.env.addSegment(0.0f, RAMP_TIME_MS);
sp.player.start();
}
}
}
}
}
示例15: midiMessage
public void midiMessage(MidiMessage message) {
if(listenlane.isRecording())
{
if(table.getSelectedRow() == -1 || table.getSelectedColumn() == -1) return;
if(((table.getSelectedColumn() - 1) % TrackerTableModel.COLUMNS) != TrackerTableModel.COLUMN_NOTEORCC) return;
if(message instanceof ShortMessage)
{
ShortMessage sms = (ShortMessage)message;
if(sms.getCommand() == ShortMessage.NOTE_ON || sms.getCommand() == ShortMessage.NOTE_OFF )
{
int note = sms.getData1();
int vel = sms.getData2();
if(sms.getCommand() == ShortMessage.NOTE_OFF) vel = 0;
if(vel > 0)
{
int row = table.getSelectedRow();
int col = tableModel.tableColumnToTrackerColumn(table.getSelectedColumn());
part.getEditHistoryContainer().mark("new note");
final MultiEvent me = tableModel.getCellEvent(row, col);
if(me != null)
part.remove(me);
NoteEvent event = new NoteEvent(part,tableModel.getTickForRow(row),note,vel,1,(long)(tableModel.ticksPerRow*tableModel.getEditDuration()));
event.setTrackerColumn(col);
part.add(event);
part.getEditHistoryContainer().notifyEditHistoryListeners();
if(getAutomaticRowJump()>0 )
table.changeSelection(table.getSelectedRow()+getAutomaticRowJump(),table.getSelectedColumn(),false,false);
}
}
}
}
}