final JToolBar tbMonitoring;
final TimeLabel lbTime;
final MessageFormat frmtPeak = new MessageFormat( getResourceString( "msgPeak" ), Locale.US ); // XXX Locale.US
final Object[] peakArgs = new Object[1];
final JRootPane rp = getRootPane();
final InputMap imap = rp.getInputMap( JComponent.WHEN_IN_FOCUSED_WINDOW );
final ActionMap amap = rp.getActionMap();
final JButton ggAbort, ggRecord, ggStop, ggClose;
final int myMeta = BasicMenuFactory.MENU_SHORTCUT == InputEvent.CTRL_MASK ?
InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK : BasicMenuFactory.MENU_SHORTCUT; // META on Mac, CTRL+SHIFT on PC
// use same encoding as parent document
encodingString = (displayAFD.sampleFormat == AudioFileDescr.FORMAT_INT ? "int" : "float") +
String.valueOf( displayAFD.bitsPerSample );
//encodingString = "float32";
audioPrefs = app.getUserPrefs().node( PrefsUtil.NODE_AUDIO );
classPrefs = app.getUserPrefs().node( className.substring( className.lastIndexOf( '.' ) + 1 ));
recPane = new SpringPanel( 4, 2, 4, 2 );
// affp = new AudioFileFormatPane( AudioFileFormatPane.ENCODING );
// recPane.gridAdd( new JLabel( getResourceString( "labelFormat" ), SwingConstants.RIGHT ), 0, 1 );
// recPane.gridAdd( affp, 1, 1 );
ggRecordConfig = new PrefComboBox();
ggRecordConfig.setFocusable( false );
lbPeak = new JLabel();
actionPeakReset = new ActionPeakReset();
ggPeakReset = new JButton( actionPeakReset );
ggPeakReset.setFocusable( false );
lbTime = new TimeLabel();
tbMonitoring = new JToolBar();
tbMonitoring.setFloatable( false );
ggMonitoring = new JToggleButton( new ActionMonitoring() );
ggMonitoring.setFocusable( false );
tbMonitoring.add( ggMonitoring );
recPane.gridAdd( lbTime, 1, 0, -2, 1 );
recPane.gridAdd( new JLabel( getResourceString( "labelRecInputs" ), SwingConstants.RIGHT ), 0, 1 );
recPane.gridAdd( ggRecordConfig, 1, 1, -1, 1 );
recPane.gridAdd( tbMonitoring, 2, 1 );
recPane.gridAdd( new JLabel( getResourceString( "labelHeadroom" ) + " :", SwingConstants.RIGHT ), 0, 2 );
recPane.gridAdd( lbPeak, 1, 2 );
// recPane.gridAdd( new JLabel( getResourceString( "labelDB" ), SwingConstants.RIGHT ), 2, 1 );
recPane.gridAdd( ggPeakReset, 2, 2, -1, 1 );
refillConfigs();
// affp.setPreferences( classPrefs );
ggRecordConfig.setPreferences( classPrefs, KEY_CONFIG );
recPane.makeCompactGrid();
butPane = new JPanel(); // new FlowLayout( FlowLayout.TRAILING ));
butPane.setLayout( new BoxLayout( butPane, BoxLayout.X_AXIS ));
actionRecord = new ActionRecord();
actionStop = new ActionStop();
actionAbort = new ActionAbort();
actionClose = new ActionClose();
butPane.add( new HelpButton( "RecorderDialog" ));
butPane.add( Box.createHorizontalGlue() );
ggAbort = new JButton( actionAbort );
ggAbort.setFocusable( false );
butPane.add( ggAbort );
ggRecord = new JButton( actionRecord );
ggRecord.setFocusable( false );
butPane.add( ggRecord );
ggStop = new JButton( actionStop );
ggStop.setFocusable( false );
butPane.add( ggStop );
ggClose = new JButton( actionClose );
ggClose.setFocusable( false );
butPane.add( ggClose );
butPane.add( CoverGrowBox.create() );
cp.add( recPane, BorderLayout.NORTH );
cp.add( butPane, BorderLayout.SOUTH );
GUIUtil.setDeepFont( cp, app.getGraphicsHandler().getFont( GraphicsHandler.FONT_SYSTEM | GraphicsHandler.FONT_SMALL ));
// runPeakUpdate = new Runnable() {
// public void run()
// {
// peakArgs[0] = new Double( MathUtil.linearToDB( 1.0 / maxPeak ));
// lbPeak.setText( frmtPeak.format( peakArgs ));
// }
// };
// runPeakUpdate.run(); // initially reset peak hold
meterTimer = new Timer( 100, new ActionListener() {
public void actionPerformed( ActionEvent e )
{
final float value = docFrame.getMaxMeterHold();
final boolean valueClip = value > -0.2f;
peakArgs[0] = new Float( value );
lbPeak.setText( frmtPeak.format( peakArgs ));
if( valueClip && !clipped ) {
clipped = valueClip;
lbPeak.setForeground( Color.red );
}
}
});
recLenTimer = new RecLenTimer( lbTime, recFrames, doc.timeline.getRate() );
// cSetNRespBody = new OSCListener() {
// public void messageReceived( OSCMessage msg, SocketAddress sender, long time )
// {
// final int busIndex = ((Number) msg.getArg( 0 )).intValue();
// final Context ct = RecorderDialog.this.ct; // quasi sync
//
// if( (ct == null) || (busIndex != ct.busMeter.getIndex()) ) return;
//
//// final long now = System.currentTimeMillis();
//
// try {
// final int numValues = ((Number) msg.getArg( 1 )).intValue();
// if( numValues != meterValues.length ) {
// meterValues = new float[ numValues ];
// }
//
// for( int i = 0; i < meterValues.length; i++ ) {
// meterValues[ i ] = ((Number) msg.getArg( i + 2 )).floatValue();
// }
//
// meterUpdate();
// }
//// catch( IOException e1 ) {
//// printError( "Receive /c_setn", e1 );
//// }
// catch( ClassCastException e2 ) {
// printError( "Receive /c_setn", e2 );
// }
// }
// };
// ---- meters -----
// meterTimer = new javax.swing.Timer( 33, new ActionListener() {
// public void actionPerformed( ActionEvent e )
// {
// try {
// if( (server != null) && (ct != null) ) server.sendMsg( ct.meterBangMsg );
// }
// catch( IOException e1 ) {}
// }
// });
setDefaultCloseOperation( DO_NOTHING_ON_CLOSE );
// root.addComponent( Main.COMP_RECORDER, this );
server = superCollider.getServer();
player = superCollider.getPlayerForDocument( doc );
if( (server == null) || (player == null) || !server.isRunning() ) {
throw new IOException( getResourceString( "errServerNotRunning" ));
}
osc = new OSCRouterWrapper( doc, this );
// ---- listeners -----
winListener = new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
if( !isRecording ) {
disposeRecorder();
}
}
};
addWindowListener( winListener );
superCollider.addServerListener( this );
// player.addMeterListener( this );
// player.setMetering( true );
nw = superCollider.getNodeWatcher();
nw.addListener( this );
// ---- keyboard shortcuts ----
imap.put( KeyStroke.getKeyStroke( KeyEvent.VK_R, myMeta ), "record" ); // VK_SPACE doesn't work (WHY?)
// amap.put( "record", actionRecord );
amap.put( "record", new DoClickAction( ggRecord ));
imap.put( KeyStroke.getKeyStroke( KeyEvent.VK_PERIOD, myMeta ), "abort" );
// amap.put( "abort", actionAbort );
amap.put( "abort", new DoClickAction( ggAbort ));
imap.put( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, myMeta ), "stop" );
// amap.put( "stop", actionStop );
amap.put( "stop", new DoClickAction( ggStop ));
imap.put( KeyStroke.getKeyStroke( KeyEvent.VK_ESCAPE, 0 ), "close" );
amap.put( "close", actionClose );
docFrame.setForceMeters( true );
player.setActiveInput( true );
meterTimer.start();