Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
development:realtime:buffer_java [2015/03/29 23:27]
robert
development:realtime:buffer_java [2017/08/17 11:21]
127.0.0.1 external edit
Line 1: Line 1:
 +
 {{tag>​java realtime development}} {{tag>​java realtime development}}
  
 ====== FieldTrip buffer Java interface ====== ====== FieldTrip buffer Java interface ======
  
-===== Client side pure Java implementation =====+Because the tools listed here are fairly simple, studying their [[http://​code.google.com/​p/​fieldtrip/​source/​browse/​trunk/​realtime/​src/​buffer/​java|source code]] is a good way to learn about the Java interface to the FieldTrip buffer.
  
-The directory ''​development/​realtime/​buffer/​java''​ contains a couple of Java classes that implement a client-side interface to the FieldTrip buffer (socket connections only). The classes wrap FieldTrip-style header structures, events, and client connections to a server.+===== Java implementation of the Buffer Server =====
  
-There are also some Java-based tools for writing [[[[java_event|events]] ​to the buffer.+The directory ''​realtime/​src/​buffer/​java/​bufferserver''​ contains a Java implementation of the buffer server. 
 + 
 +===== Java implementation of the Buffer Client ===== 
 + 
 +The directory ''​realtime/​src/​buffer/​java''​ contains a couple of Java classes that implement a client-side interface ​to the FieldTrip ​buffer ​(socket connections only). The classes wrap FieldTrip-style header structures, events, and client connections to a server.
  
 The following Java code example demonstrates how to use the interface: The following Java code example demonstrates how to use the interface:
Line 58: Line 63:
 } }
 </​code>​ </​code>​
 +
 +===== Writing FieldTrip buffer events =====
 +
 +There are also a couple of tools for translating events such as incoming MIDI messages or GUI button presses into FieldTrip events. For all tools listed below, the ''​sample''​ field of the written events will be automatically inserted (either by the server or polling for the current number of samples), and the ''​offset''​ and ''​duration''​ fields will be set to zero.
 +
 +Because the tools listed here are fairly simple, studying their [[http://​code.google.com/​p/​fieldtrip/​source/​browse/​trunk/​realtime/​src/​buffer/​java|source code]] is also a good way to learn about the [[development:​realtime:​buffer_java|Java interface]] to the FieldTrip buffer.
 +
 +==== MidiToBuffer ====
 +
 +The class ''​MidiToBuffer''​ can be used to listen on a MIDI in device for messages, and write them to a FieldTrip buffer. You should start the tool from the command line like (note the colon between hostname and port):
 +
 +  java MidiToBuffer localhost:​1972
 +  ​
 +The program will list the available MIDI devices, but it will not let you choose one: It seems you can only do that when your MIDI devices have both an input and output, which some devices don't. However, you should be able to modify the sound.properties file of your JRE to pick a MIDI port.
 +
 +In any case, MIDI events will be written with a type='​MIDI'​ and a value that has the form of an uint8 array. For a Note-on message on channel 1, with key=64 and velocity=100 for example, you would receive
 +  event.type ​ = '​MIDI'​
 +  event.value = [144 64 100]
 +  ​
 +On [[http://​www.midi.org/​techspecs/​midimessages.php|www.midi.org]] you can find a technical description of MIDI messages.
 +
 +==== MarkerGUI ====
 +
 +The ''​MarkerGUI''​ class can be used to insert events into a FieldTrip buffer by typing a ''​type''​ and a ''​value''​ string into GUI input fields, and pressing a button. This is mostly useful for debugging online paradigms, or maybe to control realtime applications that use buffer events for communication between each other. You can start the program from the command line by typing
 +
 +  java MarkerGUI [hostname:​port]
 +
 +If you leave out the optional argument, ''​localhost:​1972''​ will be used as the default. However, you //need// to connect to the buffer server, and can disconnect, change the address, and re-connect at any time, using the GUI. The ''​Address''​ input field will have a light green background as long as the application is connected to the buffer server. In case of errors during writing events, the connection will be closed automatically.
 +
 +{{:​development:​realtime:​markergui.png|}}
 +
 +==== Compilation ====
 +
 +The simplest way to compile the Java tools is to change to the directory ''​realtime/​src/​buffer/​java''​ and just to type 
 +  javac *.java
 +We have only tested JDK 6 (standard edition), but earlier versions might work as well.