voxforge.org
VoxForge Dev

Changeset 2469

Show
Ignore:
Timestamp:
03/18/08 14:04:31 (5 months ago)
Author:
kmaclean
Message:

SpeechSubmission refactor to use array for prompt list - working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/SpeechSubmission/VFSpeechSubmission/java/src/speechrecorder/CapturePlayback.java

    r2468 r2469  
    573573     
    574574        int maxWidth = 40; 
    575         // !!!!!! 
     575 
    576576        JPanel promptPanelA[] = new JPanel[numberofPrompts];  
    577577        JPanel promptInnerPanelA[] = new JPanel[numberofPrompts];    
    578578         
    579         for (int i = 1; i < numberofPrompts; i++) { 
     579        for (int i = 0; i < numberofPrompts; i++) { 
    580580                promptPanelA[i] = new JPanel(); 
    581581                promptPanelA[i].setLayout(new FlowLayout(FlowLayout.LEFT));     
    582582                promptInnerPanelA [i]= new JPanel();  
    583583                promptInnerPanelA[i].setBorder(BorderFactory.createLineBorder (voxforgeColour, 1)); 
     584                //promptInnerPanelA[i].add(new MultiLineLabel(promptPanelA[i], i+":"+this.promptA[i], maxWidth)); 
    584585                promptInnerPanelA[i].add(new MultiLineLabel(promptPanelA[i], this.promptA[i], maxWidth)); 
    585586                promptPanelA[i].add(promptInnerPanelA[i]); 
    586587                playA[i] = addButton(playButton, promptPanelA[i], false); 
    587                 captA[i] = addButton(recordButton, promptPanelA[i], false); 
     588                if (i==0) { 
     589                        captA[i] = addButton(recordButton, promptPanelA[i], true); // only turn on first record button  
     590                } else { 
     591                        captA[i] = addButton(recordButton, promptPanelA[i], false); 
     592                } 
    588593                prompts.add(promptPanelA[i]);   
    589594        } 
     
    799804        b.addActionListener(this); 
    800805        p.add(b); 
     806        // !!!!!! 
     807        b.setEnabled(state); 
     808        // !!!!!! 
    801809        return b; 
    802810    } 
     
    807815                playA[i].setEnabled(false);  
    808816                captA[i].setEnabled(false);  
     817            //System.err.println("setButtonsOff" + "playA" + i + playA[i].isEnabled()+ ";captA" + i + captA[i].isEnabled());// !!!!!! 
    809818        } 
    810819        /* 
     
    835844        // !!!!!! 
    836845        for (int i = 0; i < numberofPrompts; i++) { 
    837                 playA[i].setEnabled(false);  
    838846                if (playA[i].isEnabled()) {play_stateA [i] = true;} else {play_stateA [i] = false;} 
    839847                if (captA[i].isEnabled()) {capt_stateA [i] = true;} else {capt_stateA [i] = false;} 
     848            //System.err.println("saveButtonState" + "playA" + i + playA[i].isEnabled()+ ";captA" + i + captA[i].isEnabled());// !!!!!! 
    840849        } 
    841850        /* 
     
    866875        // !!!!!! 
    867876        for (int i = 0; i < numberofPrompts; i++) { 
    868                 playA[i].setEnabled(false);  
    869                 if (play_stateA[i]) {playA[i].setEnabled(true);} else {playA[i].setEnabled(false);} 
     877                if (play_stateA[i]) {playA[i].setEnabled(true);} else {playA[i].setEnabled(false);} 
    870878                if (capt_stateA[i]) {captA[i].setEnabled(true);} else {captA[i].setEnabled(false);} 
     879            // System.err.println("restoreButtonState" + "playA" + i + playA[i].isEnabled()+ ";captA" + i + captA[i].isEnabled());// !!!!!! 
    871880        } 
    872881        /* 
     
    893902        !!!!!! */  
    894903    } 
    895  
     904    // !!!!!! 
     905    public boolean equals(Object obj) { 
     906        for (int i = 0; i < numberofPrompts; i++) { 
     907            if (obj.equals(playA[i])) { 
     908                return (this == obj); 
     909            } 
     910        } 
     911        return (this == obj); 
     912        } 
     913    // !!!!!! 
    896914    public void actionPerformed(ActionEvent e) { 
    897915        Object obj = e.getSource(); 
     
    899917// ################### Play #######################################        
    900918        // !!!!!! 
    901        if (obj.equals(playA)) { // does not work!!!!!! 
    902                 System.err.println("Object: playA"); 
    903  
    904                 for (int i = 0; i < numberofPrompts; i++) { 
    905                     if (obj.equals(playA[i])) { 
    906                         if (playA[i].getText().startsWith(playButton)) { 
    907                             wavFile = wavFileA[i];       
    908                             duration = durationA[i]; 
    909                             totalBytesWritten = totalBytesWrittenA[i]; 
    910                             System.err.println("=== Play1 ===");// !!!!!! 
    911                             playback.start(); 
    912                                 System.err.println("duration:" + duration); 
    913                             fileName = promptidA[i];   
    914                             samplingGraph.start(); 
    915                             captA[i].setEnabled(false); 
    916                             playA[i].setText(stopButton); 
    917                         } else { 
    918                             playback.stop(); 
    919                             samplingGraph.stop(); 
    920                             captA[i].setEnabled(true); 
    921                             playA[i].setText(playButton); 
     919        for (int i = 0; i < numberofPrompts; i++) { 
     920            if (obj.equals(playA[i])) { 
     921                if (playA[i].getText().startsWith(playButton)) { 
     922                    wavFile = wavFileA[i];       
     923                    duration = durationA[i]; 
     924                    totalBytesWritten = totalBytesWrittenA[i]; 
     925                    System.err.println("=== Play" + i + "===");// !!!!!! 
     926                    playback.start(); 
     927                        System.err.println("duration:" + duration); 
     928                    fileName = promptidA[i];   
     929                    samplingGraph.start(); 
     930                    // !!!!!! 
     931                        saveButtonState();  
     932                        setButtonsOff(); 
     933                    captA[i].setEnabled(false); 
     934                    playA[i].setEnabled(true); 
     935                    playA[i].setText(stopButton); 
     936                        // !!!!!! 
     937                } else { 
     938                    playback.stop(); 
     939                    samplingGraph.stop(); 
     940                    // !!!!!! 
     941                        restoreButtonState();  
     942                        // !!!!!! 
     943                    captA[i].setEnabled(true); 
     944                    playA[i].setText(playButton); 
     945                } 
     946            } 
     947        } 
     948   
     949            for (int x = 0; x < numberofPrompts; x++) { 
     950                if (obj.equals(captA[x])) { 
     951                    if (captA[x].getText().startsWith(recordButton)) { 
     952                        file = null; 
     953                        wavFile = wavFileA[x];   
     954                                System.err.println("=== Record" + x + "==="); // !!!!!! 
     955                        capture.start(uploadWavFileA[x]);   
     956                        fileName = promptidA[x]; 
     957                        samplingGraph.start(); 
     958                        saveButtonState();  
     959                        setButtonsOff();  
     960                        captA[x].setEnabled(true);     
     961                        captA[x].setText(stopButton); 
     962                        moreInfoB.setEnabled(false);   
     963                        aboutB.setEnabled(false);  
     964                    } else { 
     965                        lines.removeAllElements();   
     966                        capture.stop(); 
     967                        totalBytesWrittenA[x] = totalBytesWritten; // !!!!!! 
     968                        durationA[x]= totalBytesWritten / (double) (format.getSampleRate() * format.getSampleSizeInBits()/ 8); 
     969                                System.err.println("duration1:" + durationA[x]); 
     970                        samplingGraph.stop(); 
     971                        restoreButtonState();  
     972                        playA[x].setEnabled(true); 
     973                        captA[x].setText(recordButton); 
     974                        moreInfoB.setEnabled(true);   
     975                        aboutB.setEnabled(true);  
     976                        captA[x].setEnabled(true); 
     977                        if (x < numberofPrompts-1) { 
     978                                captA[x+1].setEnabled(true); 
     979                        } 
     980                        if (x == numberofPrompts-1) { 
     981                                uploadB.setEnabled(true); 
    922982                        } 
    923983                    } 
    924                 } 
    925        } else if (obj.equals(captA)) {// does not work!!!!!! 
    926                 System.err.println("Object: captA"); 
    927                 for (int x = 0; x < numberofPrompts; x++) { 
    928                     if (obj.equals(captA[x])) { 
    929                         if (captA[x].getText().startsWith(recordButton)) { 
    930                             file = null; 
    931                             wavFile = wavFileA[x];   
    932                                 System.err.println("=== Record1 ==="); // !!!!!! 
    933                             capture.start(uploadWavFileA[x]);   
    934                             fileName = promptidA[x]; 
    935                             samplingGraph.start(); 
    936                             saveButtonState();  
    937                             setButtonsOff();  
    938                             captA[x].setEnabled(true);     
    939                             captA[x].setText(stopButton); 
    940                             moreInfoB.setEnabled(false);   
    941                             aboutB.setEnabled(false);  
    942                         } else { 
    943                             lines.removeAllElements();   
    944                             capture.stop(); 
    945                             totalBytesWrittenA[x] = totalBytesWritten; // !!!!!! 
    946                                 durationA[x]= totalBytesWritten / (double) (format.getSampleRate() * format.getSampleSizeInBits()/ 8); 
    947                                 System.err.println("duration1:" + durationA[x]); 
    948                                 samplingGraph.stop(); 
    949                             restoreButtonState();  
    950                             playA[x].setEnabled(true); 
    951                             captA[x].setText(recordButton); 
    952                             moreInfoB.setEnabled(true);   
    953                             aboutB.setEnabled(true);  
    954                             captA[x].setEnabled(true); 
    955                         } 
    956                       }  
    957                 } 
    958         }  
    959        /*  
     984                }  
     985            } 
     986      /*  
    960987       if (obj.equals(play1)) { 
    961988            if (play1.getText().startsWith(playButton)) { 
     
    14421469          !!!!!! */ 
    14431470//          ################### Upload #######################################                
    1444         else if (obj.equals(uploadB)) { 
     1471  //      else if (obj.equals(uploadB)) { 
    14451472                //!!!!!! 
     1473            if (obj.equals(uploadB)) {  
    14461474                for (int i = 0; i < numberofPrompts; i++) { 
    14471475                        playA[i].setEnabled(false); 
     
    17241752                    } 
    17251753                                        outbaos.write(data, 0, numBytesRead); 
    1726                                         // !!!!!! 
    17271754                                /// System.err.println("numBytesRead" + numBytesRead); 
    1728                                         // !!!!!! 
    17291755                } catch (Exception e) { 
    17301756                    shutDown("Error during playback: " + e); 
     
    17331759            }        
    17341760            byte audioBytes[] = outbaos.toByteArray(); 
    1735             // !!!!!! 
    17361761                // debug System.err.println("outbaos size:" + outbaos.size());             
    17371762                outbaos.reset(); 
    17381763                outbaos = null; 
    1739                 // !!!!!!  
    17401764            samplingGraph.createWaveForm(audioBytes);  
    17411765            samplingGraph.repaint(); 
     
    17721796 
    17731797            shutDown(null); 
     1798            // !!!!! 
     1799            restoreButtonState();  
     1800            // !!!!!! 
    17741801        } 
    17751802    } // End class Playback