本文整理汇总了Java中javax.sound.midi.ShortMessage.PROGRAM_CHANGE属性的典型用法代码示例。如果您正苦于以下问题:Java ShortMessage.PROGRAM_CHANGE属性的具体用法?Java ShortMessage.PROGRAM_CHANGE怎么用?Java ShortMessage.PROGRAM_CHANGE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.sound.midi.ShortMessage
的用法示例。
在下文中一共展示了ShortMessage.PROGRAM_CHANGE属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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));
}
}
示例3: 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;
}
}
示例4: initialize
private void initialize() {
try {
NativeLibLoader.loadNativeLibs();
} catch (Throwable ex) {
Logger.getLogger(FrinikaJVSTSynth.class.getName()).log(Level.SEVERE, null, ex);
}
receiver = new Receiver() {
public void send(MidiMessage message, long timeStamp) {
if(vst!=null && ShortMessage.class.isInstance(message))
{
ShortMessage shm = (ShortMessage) message;
switch(shm.getCommand())
{
case ShortMessage.PROGRAM_CHANGE:
program = shm.getData1();
vst.setProgram(program%128+(bank*128));
break;
default:
vst.queueMidiMessage(shm);
}
}
}
public void close() {
throw new UnsupportedOperationException("Not supported yet.");
}
};
}
示例5: processMessage
public void processMessage(int ch, int cmd, int data1, int data2) {
synchronized (synth.control_mutex) {
activity();
}
if (cmd == 0xF0) {
int status = cmd | ch;
switch (status) {
case ShortMessage.ACTIVE_SENSING:
synchronized (synth.control_mutex) {
active_sensing_on = true;
}
break;
default:
break;
}
return;
}
SoftChannel[] channels = synth.channels;
if (ch >= channels.length)
return;
SoftChannel softchannel = channels[ch];
switch (cmd) {
case ShortMessage.NOTE_ON:
if(delay_midievent != 0)
softchannel.noteOn(data1, data2, delay_midievent);
else
softchannel.noteOn(data1, data2);
break;
case ShortMessage.NOTE_OFF:
softchannel.noteOff(data1, data2);
break;
case ShortMessage.POLY_PRESSURE:
softchannel.setPolyPressure(data1, data2);
break;
case ShortMessage.CONTROL_CHANGE:
softchannel.controlChange(data1, data2);
break;
case ShortMessage.PROGRAM_CHANGE:
softchannel.programChange(data1);
break;
case ShortMessage.CHANNEL_PRESSURE:
softchannel.setChannelPressure(data1);
break;
case ShortMessage.PITCH_BEND:
softchannel.setPitchBend(data1 + data2 * 128);
break;
default:
break;
}
}
示例6: getPatchs
private static List<Patch> getPatchs(List<MidiEvent> events){
Patch[] channels = new Patch[16];
Iterator<MidiEvent> it = events.iterator();
while(it.hasNext()){
MidiEvent event = (MidiEvent)it.next();
MidiMessage msg = event.getMessage();
if( msg instanceof ShortMessage ){
ShortMessage shortMessage = (ShortMessage)msg;
int channel = shortMessage.getChannel();
if( channel >= 0 && channel < channels.length ){
int command = shortMessage.getCommand();
int data1 = shortMessage.getData1();
int data2 = shortMessage.getData2();
int bank = (command == ShortMessage.CONTROL_CHANGE && data1 == MidiControllers.BANK_SELECT ? data2 : -1);
int program = (command == ShortMessage.PROGRAM_CHANGE ? data1 : -1);
if( bank >= 0 || program >= 0 ){
if( bank < 0 ){
bank = (channels[channel] != null ? channels[channel].getBank() : 0);
}
if( program < 0 ){
program = (channels[channel] != null ? channels[channel].getProgram() : 0);
}
channels[channel] = new Patch(bank, program);
}
}
}
}
List<Patch> patchs = new ArrayList<Patch>();
for( int i = 0 ; i < channels.length ; i ++ ){
if( channels[i] != null ){
boolean patchExists = false;
Iterator<Patch> patchIt = patchs.iterator();
while( patchIt.hasNext() ){
Patch patch = (Patch) patchIt.next();
if( patch.getBank() == channels[i].getBank() && patch.getProgram() == channels[i].getProgram() ){
patchExists = true;
}
}
if(!patchExists ){
patchs.add(channels[i]);
}
}
}
patchs.add(new Patch(128, 0));
return patchs;
}
示例7: processMessage
public void processMessage(int ch, int cmd, int data1, int data2) {
synchronized (synth.control_mutex) {
activity();
}
if (cmd == 0xF0) {
int status = cmd | ch;
switch (status) {
case ShortMessage.ACTIVE_SENSING:
synchronized (synth.control_mutex) {
active_sensing_on = true;
}
break;
default:
break;
}
return;
}
SoftChannel[] channels = synth.channels;
if (ch >= channels.length)
return;
SoftChannel softchannel = channels[ch];
switch (cmd) {
case ShortMessage.NOTE_ON:
softchannel.noteOn(data1, data2);
break;
case ShortMessage.NOTE_OFF:
softchannel.noteOff(data1, data2);
break;
case ShortMessage.POLY_PRESSURE:
softchannel.setPolyPressure(data1, data2);
break;
case ShortMessage.CONTROL_CHANGE:
softchannel.controlChange(data1, data2);
break;
case ShortMessage.PROGRAM_CHANGE:
softchannel.programChange(data1);
break;
case ShortMessage.CHANNEL_PRESSURE:
softchannel.setChannelPressure(data1);
break;
case ShortMessage.PITCH_BEND:
softchannel.setPitchBend(data1 + data2 * 128);
break;
default:
break;
}
}
示例8: decodeMessage
private static String decodeMessage(ShortMessage message) {
String result = null;
switch (message.getCommand()) {
case ShortMessage.NOTE_OFF:
result = "note Off " + keyName(message.getData1()) + " velocity: " + message.getData2();
break;
case ShortMessage.NOTE_ON:
result = "note On " + keyName(message.getData1()) + " velocity: " + message.getData2();
break;
case ShortMessage.POLY_PRESSURE:
result = "polyphonic key pressure " + keyName(message.getData1()) + " pressure: " + message.getData2();
break;
case ShortMessage.CONTROL_CHANGE:
if(message.getData1() == 1) result = "Using channel " + (message.getData2() >> 3);
else result = "control change " + message.getData1() + " value: " + message.getData2();
break;
case ShortMessage.PROGRAM_CHANGE:
result = "program change " + message.getData1();
break;
case 0xd0:
result = "key pressure " + keyName(message.getData1()) + " pressure: " + message.getData2();
break;
case ShortMessage.PITCH_BEND:
result = "pitch wheel change " + MidiIO.toInt14(message.getData1(), message.getData2());
break;
case 0xF0:
result = SYSTEM_MESSAGES[message.getChannel()];
switch (message.getChannel()) {
case 0x1:
int nQType = (message.getData1() & 0x70) >> 4;
int nQData = message.getData1() & 0x0F;
if (nQType == 7)
nQData = nQData & 0x1;
result += QUARTER_FRAME_MESSAGES[nQType] + nQData;
if (nQType == 7) {
int nFrameType = (message.getData1() & 0x06) >> 1;
result += ", frame type: " + FRAME_TYPE[nFrameType];
}
break;
case 0x2:
result += MidiIO.toInt14(message.getData1(), message.getData2());
break;
case 0x3:
result += message.getData1();
break;
}
break;
default:
result = "unknown message: status = " + message.getStatus() + ", byte1 = " + message.getData1() + ", byte2 = " + message.getData2();
break;
}
if (message.getCommand() != 0xF0)
result = "channel " + (message.getChannel() + 1) + ": " + result;
return "["+toHexString(message)+"] "+ result;
}
示例9: encodeCommand
/**
* Encodes the midi command from a readable string
*
* @param command
* The command as readable string
* @return The midi encoded command, -1 if it could not be encoded
*/
private static int encodeCommand(String command) {
int result;
switch (command) {
case NOTE_OFF:
result = ShortMessage.NOTE_OFF;
break;
case NOTE_ON:
result = ShortMessage.NOTE_ON;
break;
case POLYPHONIC_KEY_PRESSURE:
result = ShortMessage.POLY_PRESSURE;
break;
case CONTROL_CHANGE:
result = ShortMessage.CONTROL_CHANGE;
break;
case PROGRAM_CHANGE:
result = ShortMessage.PROGRAM_CHANGE;
break;
case KEY_PRESSURE:
result = 0xd0;
break;
case PITCH_WHEEL_CHANGE:
result = 0xe0;
break;
case SYSTEM_MESSAGE:
result = 0xF0;
default:
result = -1;
break;
}
return result;
}
示例10: expectedDataLength
/**
* Determine how many data bytes are expected for a given MIDI message other than a SYSEX message, which varies.
*
* @param status the status byte introducing the MIDI message.
*
* @return the number of data bytes which must be received for the message to be complete.
*
* @throws InvalidMidiDataException if the status byte is not valid.
*/
private int expectedDataLength (byte status) throws InvalidMidiDataException {
// system common and system real-time messages
switch( status &0xFF ) {
case ShortMessage.TUNE_REQUEST:
case ShortMessage.END_OF_EXCLUSIVE:
// System real-time messages
case ShortMessage.TIMING_CLOCK:
case 0xF9: // Undefined
case ShortMessage.START:
case ShortMessage.CONTINUE:
case ShortMessage.STOP:
case 0xFD: // Undefined
case ShortMessage.ACTIVE_SENSING:
case ShortMessage.SYSTEM_RESET:
return 0;
case ShortMessage.MIDI_TIME_CODE:
case ShortMessage.SONG_SELECT:
return 1;
case ShortMessage.SONG_POSITION_POINTER:
return 2;
default: // Fall through to next switch
}
// channel voice and mode messages
switch( status & 0xF0 ) {
case ShortMessage.NOTE_OFF:
case ShortMessage.NOTE_ON:
case ShortMessage.POLY_PRESSURE:
case ShortMessage.CONTROL_CHANGE:
case ShortMessage.PITCH_BEND:
return 2;
case ShortMessage.PROGRAM_CHANGE:
case ShortMessage.CHANNEL_PRESSURE:
return 1;
default:
throw new InvalidMidiDataException("Invalid status byte: " + status);
}
}
示例11: updateStatus
public void updateStatus(MidiMessage msg)
{
if(msg instanceof ShortMessage)
{
ShortMessage sms = (ShortMessage)msg;
switch (sms.getCommand()) {
case ShortMessage.NOTE_ON:
int ix = activenotes.indexOf(new Integer(sms.getData1()));
if(ix != -1)
{
activenotes.remove(ix);
activenotes_velocity.remove(ix);
}
if(sms.getData2()>0)
{
activenotes.add(new Integer(sms.getData1()));
activenotes_velocity.add(new Integer(sms.getData2()));
}
break;
case ShortMessage.NOTE_OFF:
ix = activenotes.indexOf(new Integer(sms.getData1()));
if(ix != -1)
{
activenotes.remove(ix);
activenotes_velocity.remove(ix);
}
break;
case ShortMessage.PROGRAM_CHANGE:
program = sms.getData1();
break;
case ShortMessage.PITCH_BEND:
pitchbend_data1 = sms.getData1();
pitchbend_data2 = sms.getData2();
break;
case ShortMessage.CONTROL_CHANGE:
ix = controls.indexOf(new Integer(sms.getData1()));
if(ix != -1)
{
controls.remove(ix);
controls_values.remove(ix);
}
controls.add(sms.getData1());
controls_values.add(sms.getData2());
break;
default:
break;
}
}
}
示例12: getProgram
public MyPatch getProgram() {
MyPatch patch = programEvent.getPatch();
if (patch != null) {
return patch;
}
FrinikaTrackWrapper track = ftw;
int count = track.size();
for (int i = 0; i < count; i++) {
MidiEvent event = track.get(i);
if (event.getTick() != 0) {
return patch;
}
MidiMessage msg = event.getMessage();
if (msg instanceof ShortMessage) {
ShortMessage sms = (ShortMessage) msg;
if (sms.getCommand() == ShortMessage.PROGRAM_CHANGE) {
if (patch == null) {
patch = new MyPatch(0, 0, 0);
}
patch.prog = sms.getData1();
}
if (sms.getCommand() == ShortMessage.CONTROL_CHANGE) {
if (sms.getData1() == 0) {
if (patch == null) {
patch = new MyPatch(0, 0, 0);
}
patch.msb = sms.getData2();
}
if (sms.getData1() == 0x20) {
if (patch == null) {
patch = new MyPatch(0, 0, 0);
}
patch.lsb = sms.getData2();
}
}
}
}
return patch;
}
示例13: songChanged
public void songChanged()
{
clear();
if (sequencer.getSequence() == null)
return;
Track[] tracks = sequencer.getSequence().getTracks();
trackCheckBoxes = new JCheckBox[tracks.length];
for (int i = 0; i < tracks.length; i++)
{
Track track = tracks[i];
// Only show tracks with at least one note
boolean hasNotes = false;
LotroInstrument instrument = LotroInstrument.DEFAULT_INSTRUMENT;
for (int j = 0; j < track.size(); j++)
{
MidiEvent evt = track.get(j);
if (evt.getMessage() instanceof ShortMessage)
{
ShortMessage m = (ShortMessage) evt.getMessage();
if (m.getCommand() == ShortMessage.NOTE_ON)
{
hasNotes = true;
}
else if (m.getCommand() == ShortMessage.PROGRAM_CHANGE)
{
for (LotroInstrument inst : LotroInstrument.values())
{
if (m.getData1() == inst.midiProgramId)
{
instrument = inst;
break;
}
}
}
}
}
if (hasNotes)
{
JCheckBox checkBox = new JCheckBox(getCheckBoxText(i));
trackCheckBoxes[i] = checkBox;
checkBox.setToolTipText(abcInfo.getPartNumber(i) + ". " + abcInfo.getPartFullName(i));
checkBox.putClientProperty(trackIndexKey, i);
checkBox.setBackground(getBackground());
checkBox.setSelected(!sequencer.getTrackMute(i));
checkBox.addActionListener(trackMuteListener);
JToggleButton soloButton = new JToggleButton("S");
soloButton.setMargin(new Insets(3, 4, 3, 3));
soloButton.setToolTipText("Play only this part (Solo)");
soloButton.putClientProperty(trackIndexKey, i);
soloButton.setBackground(getBackground());
soloButton.setSelected(sequencer.getTrackSolo(i));
soloButton.addActionListener(trackSoloListener);
JComboBox<LotroInstrument> comboBox = new JComboBox<LotroInstrument>(sortedInstruments);
comboBox.setMaximumRowCount(sortedInstruments.length);
comboBox.putClientProperty(trackIndexKey, i);
comboBox.setBackground(getBackground());
comboBox.setSelectedItem(instrument);
comboBox.addActionListener(instrumentChangeListener);
int r = layout.getNumRow() - 1;
layout.insertRow(r, TRACKLIST_ROWHEIGHT);
add(checkBox, "1, " + r);
add(soloButton, "2, " + r);
add(comboBox, "3, " + r);
}
}
revalidate();
repaint();
}