1 package net.sf.jack4j; 2 3 /* 4 Copyright (C) 2008 Ondrej Par 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU Lesser General Public License as published by 8 the Free Software Foundation; either version 2.1 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20 */ 21 22 /** 23 * MIDI port registered by {@link JackClient}. 24 * 25 * @author repa 26 * 27 */ 28 public class JackLocalMidiPort extends JackLocalPort { 29 30 static { 31 JackBridge.initializeJackBridge(); 32 } 33 34 private JackMidiPortBuffer jackMidiPortBuffer; 35 36 JackLocalMidiPort(long portHandle, JackClient client) { 37 super(portHandle, client); 38 } 39 40 /** 41 * Returns instance of {@link JackMidiPortBuffer} for this port. 42 * 43 * <p> 44 * The returned instance is <b>only valid during current process cycle</b>, 45 * and may not be cached (even if bufferSize stays the same). 46 * 47 * <p> 48 * For output buffer, you still need to call 49 * {@link JackMidiPortBuffer#clearBuffer()} before writing to the buffer. 50 * 51 * @param bufferSize 52 * current buffer size, as passed to 53 * {@link JackClient#process(int)} callback 54 * @return valid {@link JackMidiPortBuffer} object 55 * @throws JackException 56 * if the buffer can't be initialized 57 */ 58 public JackMidiPortBuffer initializeMidiBuffer(int bufferSize) throws JackException { 59 long bufferPointer = getBufferPointer(bufferSize); 60 if (jackMidiPortBuffer != null) { 61 jackMidiPortBuffer.setBufferPointer(bufferPointer); 62 } else { 63 jackMidiPortBuffer = new JackMidiPortBuffer(bufferPointer); 64 } 65 66 return jackMidiPortBuffer; 67 } 68 }