Ignore:
Timestamp:
09/23/08 16:00:42 (16 years ago)
Author:
bjn8
Message:

Refactored a class name and extended recorder widgets to have a perminant lifetime option (for optimum idea capturing!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src_apollo/org/apollo/widgets/SampleRecorder.java

    r315 r318  
    1717import java.io.IOException;
    1818import java.io.PipedInputStream;
     19import java.util.LinkedList;
     20import java.util.List;
    1921
    2022import javax.sound.sampled.AudioFormat;
     
    4951import org.expeditee.gui.Frame;
    5052import org.expeditee.gui.FrameGraphics;
     53import org.expeditee.gui.FrameMouseActions;
    5154import org.expeditee.items.ItemParentStateChangedEvent;
    5255import org.expeditee.items.Text;
    5356import org.expeditee.items.widgets.InteractiveWidget;
    5457
     58/**
     59 * Records sampled audio ... the cornerstone widget to Apollo.
     60 *
     61 * @author Brook Novak
     62 *
     63 */
    5564public class SampleRecorder extends InteractiveWidget
    5665        implements ActionListener, Observer, MultitrackLoadListener {
     
    8594        private boolean hasExplicityStopped = false;
    8695       
     96        private boolean isSelfDestructable = false;
     97       
    8798        private final static int BUTTON_HEIGHT = 50;
    8899        private final static int LABEL_HEIGHT = 30;
     
    97108       
    98109        private final static int RENDER_POINTS_PER_SECOND = 20; // how many points to render each second
     110       
     111        private final static String SELF_DESTRUCT_OFF_META = "permanent";
     112        private final static String COUNTDOWN_META = "countdown=";
     113       
    99114       
    100115        public SampleRecorder(Text source, String[] args) {
     
    105120                                COUNTDOWN_SETTINGS_HEIGHT + BUTTON_HEIGHT + LABEL_HEIGHT + AnimatedSampleGraph.GRAPH_HEIGHT + (4 * VERT_SPACING));
    106121               
     122                isSelfDestructable = !containsDataTrimmedIgnoreCase(SELF_DESTRUCT_OFF_META);
     123                int countdown = getStrippedDataInt(COUNTDOWN_META, 0);
     124                if (countdown < 0) countdown = 0;
     125                else if (countdown > MAX_COUNTDOWN_TIME)
     126                        countdown = MAX_COUNTDOWN_TIME;
     127
    107128                // Create gui layout
    108129                recordButton = new JButton();
     
    133154                countDownSpinner = new JSpinner(model);
    134155                countDownSpinner.setPreferredSize(new Dimension(50, COUNTDOWN_SETTINGS_HEIGHT));
    135                
     156                countDownSpinner.setValue(countdown);
     157
    136158                countDownSpinnerLabel = new JLabel("Count down:");
    137159                countDownSpinnerLabel.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH - 50, COUNTDOWN_SETTINGS_HEIGHT));
     
    307329                               
    308330                        } else {
    309 
    310                                 // Remove this temporary widget
    311                                 removeSelf();
     331                               
     332                                if (isSelfDestructable) {
     333                                        // Remove this temporary widget
     334                                        removeSelf();
     335                                }
    312336                       
    313337                                // Spawn an audio track using the actual bytes and audio format buffered from
     
    326350                                         if (!shouldPlayback) initiationTime = -1;
    327351                                         
    328                                          SampledTrackEvo4 trackWidget = SampledTrackEvo4.createFromMemory(
     352                                         SampledTrack trackWidget = SampledTrack.createFromMemory(
    329353                                                         audioByteReader.bufferedAudioBytes.toByteArray(),
    330354                                                         audioByteReader.audioFormat,
     
    336360                                                         null);
    337361                                         
    338                                          targetFrame.addAllItems(trackWidget.getItems());
     362                                         if (isSelfDestructable) {
     363                                                 
     364                                                 targetFrame.addAllItems(trackWidget.getItems());
     365               
     366                                         } else {
     367                                                 
     368                                                 FrameMouseActions.pickup(trackWidget.getItems());
     369                                                       
     370                                                // Reset the state
     371                                                setState(WidgetState.Ready, "Ready");
     372                                               
     373                                         }
    339374       
    340375                                         
     
    379414                return null;
    380415        }
    381        
     416
     417        @Override
     418        protected List<String> getData() {
     419
     420                List<String> data = new LinkedList<String>();
     421               
     422                if (isSelfDestructable)
     423                        data.add(SELF_DESTRUCT_OFF_META);
     424               
     425                data.add(COUNTDOWN_META + countDownSpinner.getValue());
     426
     427                return data;
     428        }
     429
    382430        @Override
    383431        protected void onParentStateChanged(int eventType) {
Note: See TracChangeset for help on using the changeset viewer.