📄 asequencer.java
字号:
/* * ASequencer.java *//* * Copyright (c) 1999, 2000 by Matthias Pfisterer <Matthias.Pfisterer@gmx.de> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */package org.tritonus.lowlevel.alsa;import java.lang.UnsupportedOperationException;import java.util.Iterator;import javax.sound.midi.MidiEvent;import javax.sound.midi.MidiMessage;import javax.sound.midi.ShortMessage;import javax.sound.midi.SysexMessage;import javax.sound.midi.MetaMessage;import javax.sound.midi.InvalidMidiDataException;import org.tritonus.TDebug;public class ASequencer extends ASequencer0{ private SystemInfo m_systemInfo; public ASequencer() { super(); } public ASequencer(String strName) { super(); setClientName(strName); } public SystemInfo getSystemInfo() { if (m_systemInfo == null) { int[] anValues = new int[4]; getSystemInfo(anValues); m_systemInfo = new SystemInfo(anValues[0], anValues[1], anValues[2], anValues[3]); } return m_systemInfo; } public ClientInfo getClientInfo() { return getClientInfo(getClientId()); } public ClientInfo getClientInfo(int nClient) { int[] anValues = new int[4]; String[] astrValues = new String[2]; int nSuccess = getClientInfo(nClient, anValues, astrValues); if (nSuccess == 0) { return new ClientInfo(anValues[0], anValues[1], astrValues[0], anValues[2], astrValues[1], anValues[3]); } else { return null; } } public Iterator getClientInfos() { return new ClientInfoIterator(); } public Iterator getPortInfos(int nClient) { return new PortInfoIterator(nClient); } public void subscribePort( int nSenderClient, int nSenderPort, int nDestClient, int nDestPort) { subscribePort( nSenderClient, nSenderPort, nDestClient, nDestPort, 0, false, false, false); } public void subscribePort( int nSenderClient, int nSenderPort, int nDestClient, int nDestPort, int nQueue, boolean bExclusive, boolean bRealtime, boolean bConvertTime) { subscribePort( nSenderClient, nSenderPort, nDestClient, nDestPort, nQueue, bExclusive, bRealtime, bConvertTime, 0, 0, 0); } /** Get the playback position of a sequencer queue. * * @return the current playback position in ticks */ public long getQueuePositionTick(int nQueue) { int[] anValues = new int[3]; long[] alValues = new long[2]; getQueueStatus(nQueue, anValues, alValues); return alValues[0]; } /** Get the playback position of a sequencer queue. * * @return the current playback position in nanoseconds */ public long getQueuePositionTime(int nQueue) { int[] anValues = new int[3]; long[] alValues = new long[2]; getQueueStatus(nQueue, anValues, alValues); return alValues[1]; } public void startQueue(int nSourcePort, int nQueue) { controlQueue(SND_SEQ_EVENT_START, nSourcePort, nQueue); } public void stopQueue(int nSourcePort, int nQueue) { controlQueue(SND_SEQ_EVENT_STOP, nSourcePort, nQueue); } /** Set the playback position of a sequencer queue. * * @param lTick the desired playback position in ticks */ public void setQueuePositionTick(int nSourcePort, int nQueue, long lTick) { controlQueue(SND_SEQ_EVENT_SETPOS_TICK, nSourcePort, nQueue, lTick); } /** Set the playback position of a sequencer queue. * * @param lTick the desired playback position in nanoseconds */ public void setQueuePositionTime(int nSourcePort, int nQueue, long lTime) { controlQueue(SND_SEQ_EVENT_SETPOS_TIME, nSourcePort, nQueue, lTime); } public void controlQueue(int nType, int nSourcePort, int nQueue) { sendQueueControlEvent( nType, SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_REL, 0, SND_SEQ_QUEUE_DIRECT, 0L, nSourcePort, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER, nQueue, 0, 0); } public void controlQueue(int nType, int nSourcePort, int nQueue, long lTime) { sendQueueControlEvent( nType, SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_REL, 0, SND_SEQ_QUEUE_DIRECT, 0L, nSourcePort, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER, nQueue, 0, lTime); } /** Returns tempo in MPQ. */ public int getQueueTempo(int nQueue) { int[] anValues = new int[2]; getQueueTempo(nQueue, anValues); return anValues[0] * anValues[1]; } /////////////////////////// sending MIDI messages public void sendNoteOffEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nVelocity) { sendNoteEventImmediately( SND_SEQ_EVENT_NOTEOFF, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nVelocity); } public void sendNoteOffEventTicked( int nQueue, long lTick, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nVelocity) { sendNoteEventTicked( SND_SEQ_EVENT_NOTEOFF, nQueue, lTick, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nVelocity); } public void sendNoteOffEventSubscribersTicked( int nQueue, long lTick, int nSourcePort, int nChannel, int nNote, int nVelocity) { sendNoteEventSubscribersTicked( SND_SEQ_EVENT_NOTEOFF, nQueue, lTick, nSourcePort, nChannel, nNote, nVelocity); } public void sendNoteOffEventSubscribersImmediately( int nSourcePort, int nChannel, int nNote, int nVelocity) { sendNoteEventSubscribersImmediately( SND_SEQ_EVENT_NOTEOFF, nSourcePort, nChannel, nNote, nVelocity); } public void sendNoteOnEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nVelocity) { sendNoteEventImmediately( SND_SEQ_EVENT_NOTEON, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nVelocity); } public void sendNoteOnEventTicked( int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nVelocity) { sendNoteEventTicked( SND_SEQ_EVENT_NOTEON, nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nVelocity); } public void sendNoteOnEventSubscribersTicked( int nQueue, long lTime, int nSourcePort, int nChannel, int nNote, int nVelocity) { sendNoteEventSubscribersTicked( SND_SEQ_EVENT_NOTEON, nQueue, lTime, nSourcePort, nChannel, nNote, nVelocity); } public void sendNoteOnEventSubscribersImmediately( int nSourcePort, int nChannel, int nNote, int nVelocity) { sendNoteEventSubscribersImmediately( SND_SEQ_EVENT_NOTEON, nSourcePort, nChannel, nNote, nVelocity); } // sendNoteEventTimed: real-time timestamp? public void sendNoteEventImmediately( int nType, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nVelocity) { sendNoteEvent( nType, SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_REL, 0, SND_SEQ_QUEUE_DIRECT, 0L, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nVelocity, 0, 0); } public void sendNoteEventTicked( int nType, int nQueue, long lTick, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nVelocity) { sendNoteEvent( nType, SND_SEQ_TIME_STAMP_TICK | SND_SEQ_TIME_MODE_ABS, 0, nQueue, lTick, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nVelocity, 0, 0); } public void sendNoteEventSubscribersTicked( int nType, int nQueue, long lTick, int nSourcePort, int nChannel, int nNote, int nVelocity) { sendNoteEvent( nType, SND_SEQ_TIME_STAMP_TICK | SND_SEQ_TIME_MODE_ABS, 0, nQueue, lTick, nSourcePort, SND_SEQ_ADDRESS_SUBSCRIBERS, SND_SEQ_ADDRESS_UNKNOWN, nChannel, nNote, nVelocity, 0, 0); } public void sendNoteEventSubscribersImmediately( int nType, int nSourcePort, int nChannel, int nNote, int nVelocity) { sendNoteEvent( nType, SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_REL, 0, SND_SEQ_QUEUE_DIRECT, 0L, nSourcePort, SND_SEQ_ADDRESS_SUBSCRIBERS, SND_SEQ_ADDRESS_UNKNOWN, nChannel, nNote, nVelocity, 0, 0); } public void sendKeyPressureEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nPressure) { sendControlEventImmediately( SND_SEQ_EVENT_KEYPRESS, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nPressure); } public void sendKeyPressureEventTicked( int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nNote, int nPressure) { sendControlEventTicked( SND_SEQ_EVENT_KEYPRESS, nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, nNote, nPressure); } public void sendKeyPressureEventSubscribersTicked( int nQueue, long lTime, int nSourcePort, int nChannel, int nNote, int nPressure) { sendControlEventSubscribersTicked( SND_SEQ_EVENT_KEYPRESS, nQueue, lTime, nSourcePort, nChannel, nNote, nPressure); } public void sendKeyPressureEventSubscribersImmediately( int nSourcePort, int nChannel, int nNote, int nPressure) { sendControlEventSubscribersImmediately( SND_SEQ_EVENT_KEYPRESS, nSourcePort, nChannel, nNote, nPressure); } public void sendControlChangeEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nControl, int nValue) { sendControlEventImmediately( SND_SEQ_EVENT_CONTROLLER, nSourcePort, nDestClient, nDestPort, nChannel, nControl, nValue); } public void sendControlChangeEventTicked( int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nControl, int nValue) { sendControlEventTicked( SND_SEQ_EVENT_CONTROLLER, nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, nControl, nValue); } public void sendControlChangeEventSubscribersTicked( int nQueue, long lTime, int nSourcePort, int nChannel, int nControl, int nValue) { sendControlEventSubscribersTicked( SND_SEQ_EVENT_CONTROLLER, nQueue, lTime, nSourcePort, nChannel, nControl, nValue); } public void sendControlChangeEventSubscribersImmediately( int nSourcePort, int nChannel, int nControl, int nValue) { sendControlEventSubscribersImmediately( SND_SEQ_EVENT_CONTROLLER, nSourcePort, nChannel, nControl, nValue); } public void sendProgramChangeEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nProgram) { sendControlEventImmediately( SND_SEQ_EVENT_PGMCHANGE, nSourcePort, nDestClient, nDestPort, nChannel, 0, nProgram); } public void sendProgramChangeEventTicked( int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nProgram) { sendControlEventTicked( SND_SEQ_EVENT_PGMCHANGE,nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, 0, nProgram); } public void sendProgramChangeEventSubscribersTicked( int nQueue, long lTime, int nSourcePort, int nChannel, int nProgram) { sendControlEventSubscribersTicked( SND_SEQ_EVENT_PGMCHANGE,nQueue, lTime, nSourcePort, nChannel, 0, nProgram); } public void sendProgramChangeEventSubscribersImmediately( int nSourcePort, int nChannel, int nProgram) { sendControlEventSubscribersImmediately( SND_SEQ_EVENT_PGMCHANGE, nSourcePort, nChannel, 0, nProgram); } /////////////////// channel pressure ///////////////// public void sendChannelPressureEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nPressure) { sendControlEventImmediately( SND_SEQ_EVENT_CHANPRESS, nSourcePort, nDestClient, nDestPort, nChannel, 0, nPressure); } public void sendChannelPressureEventTicked( int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nPressure) { sendControlEventTicked( SND_SEQ_EVENT_CHANPRESS, nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, 0, nPressure); } public void sendChannelPressureEventSubscribersTicked( int nQueue, long lTime, int nSourcePort, int nChannel, int nPressure) { sendControlEventSubscribersTicked( SND_SEQ_EVENT_CHANPRESS, nQueue, lTime, nSourcePort, nChannel, 0, nPressure); } public void sendChannelPressureEventSubscribersImmediately( int nSourcePort, int nChannel, int nPressure) { sendControlEventSubscribersImmediately( SND_SEQ_EVENT_CHANPRESS, nSourcePort, nChannel, 0, nPressure); } ////////////////// pitch bend ///////////////////// public void sendPitchBendEventImmediately( int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nPitch) { sendControlEventImmediately( SND_SEQ_EVENT_PITCHBEND, nSourcePort, nDestClient, nDestPort, nChannel, 0, nPitch); } public void sendPitchBendEventTicked( int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nPitch) { sendControlEventTicked( SND_SEQ_EVENT_PITCHBEND, nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, 0, nPitch); } public void sendPitchBendEventSubscribersTicked( int nQueue, long lTime, int nSourcePort, int nChannel, int nPitch) { sendControlEventSubscribersTicked( SND_SEQ_EVENT_PITCHBEND, nQueue, lTime, nSourcePort, nChannel, 0, nPitch); } public void sendPitchBendEventSubscribersImmediately( int nSourcePort, int nChannel, int nPitch) { sendControlEventSubscribersImmediately( SND_SEQ_EVENT_PITCHBEND, nSourcePort, nChannel, 0, nPitch); } /////////////////////// common procedures public void sendControlEventImmediately( int nType, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nParam, int nValue) { sendControlEvent( nType, SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_REL, 0, SND_SEQ_QUEUE_DIRECT, 0L, nSourcePort, nDestClient, nDestPort, nChannel, nParam, nValue); } public void sendControlEventTicked( int nType, int nQueue, long lTime, int nSourcePort, int nDestClient, int nDestPort, int nChannel, int nParam, int nValue) { sendControlEvent( nType, SND_SEQ_TIME_STAMP_TICK | SND_SEQ_TIME_MODE_ABS, 0, nQueue, lTime, nSourcePort, nDestClient, nDestPort, nChannel, nParam, nValue); } public void sendControlEventSubscribersTicked( int nType, int nQueue, long lTime, int nSourcePort, int nChannel, int nParam, int nValue) { sendControlEvent( nType, SND_SEQ_TIME_STAMP_TICK | SND_SEQ_TIME_MODE_ABS, 0, nQueue, lTime, nSourcePort, SND_SEQ_ADDRESS_SUBSCRIBERS, SND_SEQ_ADDRESS_UNKNOWN, nChannel, nParam, nValue); } public void sendControlEventSubscribersImmediately( int nType, int nSourcePort, int nChannel, int nParam, int nValue) { sendControlEvent( nType, SND_SEQ_TIME_STAMP_REAL | SND_SEQ_TIME_MODE_REL, 0, SND_SEQ_QUEUE_DIRECT, 0L, nSourcePort, SND_SEQ_ADDRESS_SUBSCRIBERS, SND_SEQ_ADDRESS_UNKNOWN, nChannel, nParam, nValue); } /* * nTempo is in us/beat */ // TODO: check if used public void sendTempoEventSubscribersTicked( int nQueue, long lTime,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -