private void sendEnvelopeFrequency(Receiver rx, int channel, byte[] regs) throws Exception { int data = (regs[0xc] & 0xff) + ((regs[0xd] << 8) & 0x0f00); data = data >> FREQ_SCALE_FACTOR; // 16 bit value, divided into 7/7/2 byte high = (byte) ((data >> 9) & 0x7f); // top 7 bits byte med = (byte) ((data >> 7) & 0x7f); // middle 7 bits byte low = (byte) (((data >> 2) & 0x03) << 5); // bottom 2 bits rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_HIGH, high), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_MED, med), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_LOW, low), -1); }
public void start() { if (receiver != null) receiver.stop(); receiver = new Receiver(server.factory).start(); if (isSenderUsed()) { if (sender != null) sender.stop(); sender = new Sender(server.factory, server.sendQueueSize()).start(); } }
private void sendLatch(Receiver rx, int channel, boolean enabled) throws Exception { byte value = enabled ? (byte) 64 : (byte) 0; if (!enabled) { // save registers for (int i = 0; i < registers.length; i++) { prevRegisters[i] = registers[i]; } } rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_LATCH, value), -1); }
private void sendFrequency(Receiver rx, int channel, byte[] regs, int startRegister) throws Exception { int data = (regs[startRegister] & 0xff) + ((regs[startRegister + 1] << 8) & 0x0f00); data = data >> FREQ_SCALE_FACTOR; byte msb = (byte) ((data >> 5) & 0x7f); // top 7 bits byte lsb = (byte) ((data << 2) & 0x7c); // lower 5 bits int cc1 = ((startRegister / 2) + CC_CHANNEL_A_FREQ_MSB); int cc2 = ((startRegister / 2) + CC_CHANNEL_A_FREQ_LSB); rx.send(new ShortMessage(CONTROL_CHANGE, channel, (byte) cc1, msb), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, (byte) cc2, lsb), -1); }
public void close() throws IOException { send_lock.lock(); try { Util.close(out, in, sock); if (receiver != null) { receiver.stop(); receiver = null; } if (sender != null) { sender.stop(); sender = null; } } finally { send_lock.unlock(); } }
public String toString() { Socket tmp_sock = sock; if (tmp_sock == null) return "<null socket>"; InetAddress local = tmp_sock.getLocalAddress(), remote = tmp_sock.getInetAddress(); String local_str = local != null ? Util.shortName(local) : "<null>"; String remote_str = remote != null ? Util.shortName(remote) : "<null>"; return String.format( "%s:%s --> %s:%s (%d secs old) [%s] [recv_buf=%d]", local_str, tmp_sock.getLocalPort(), remote_str, tmp_sock.getPort(), TimeUnit.SECONDS.convert(getTimestamp() - last_access, TimeUnit.NANOSECONDS), status(), receiver != null ? receiver.bufferSize() : 0); }
public void connect(String user, String pass) { if (!connected) { try { socket = new Socket(domain, 4446); out = new PrintWriter(socket.getOutputStream(), true); // in = new BufferedReader(new InputStreamReader(socket.getInputStream())); in = new ObjectInputStream(socket.getInputStream()); } catch (java.net.UnknownHostException e) { System.err.println("Don't know about host"); return; } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to"); return; } this.connected = true; rec = new Receiver(in); rec.start(); } }
/** * Calls the receiver callback. We do not serialize access to this method, and it may be called * concurrently by several Connection handler threads. Therefore the receiver needs to be * reentrant. */ public void receive(Address sender, byte[] data, int offset, int length) { receiver.receive(sender, data, offset, length); }
private void resetController(Receiver rx, int channel, byte[] regs) throws Exception { for (int i = 0; i < 15; i++) { regs[i] = 0; } rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_LATCH, 127), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_A_FREQ_MSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_A_FREQ_LSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_B_FREQ_MSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_B_FREQ_LSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_C_FREQ_MSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_C_FREQ_LSB, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_NOISE_FREQ, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_MIXER, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_A_LEVEL, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_B_LEVEL, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_CHANNEL_C_LEVEL, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_HIGH, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_MED, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_FREQ_LOW, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_ENVELOPE_SHAPE, 0), -1); rx.send(new ShortMessage(CONTROL_CHANGE, channel, CC_LATCH, 0), -1); }
private void sendValue(Receiver rx, int channel, byte cc, byte value) throws Exception { rx.send(new ShortMessage(CONTROL_CHANGE, channel, cc, value), -1); }
/** * Test for the presence of incoming packets. * * @return true if there are packets available to be received. */ public boolean incoming() { return rcvr.incoming(); }
/** * Retrieve the next packet from the substrate. * * @return the next incoming packet */ public Packet receive() { return rcvr.receive(); }
/** Wait for Substrate to stop. */ public void join() throws Exception { sndr.join(); rcvr.join(); }
/** Start Substrate running. */ public void start() { sndr.start(); rcvr.start(); }