Changeset 2469
- Timestamp:
- 03/18/08 14:04:31 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/SpeechSubmission/VFSpeechSubmission/java/src/speechrecorder/CapturePlayback.java
r2468 r2469 573 573 574 574 int maxWidth = 40; 575 // !!!!!! 575 576 576 JPanel promptPanelA[] = new JPanel[numberofPrompts]; 577 577 JPanel promptInnerPanelA[] = new JPanel[numberofPrompts]; 578 578 579 for (int i = 1; i < numberofPrompts; i++) {579 for (int i = 0; i < numberofPrompts; i++) { 580 580 promptPanelA[i] = new JPanel(); 581 581 promptPanelA[i].setLayout(new FlowLayout(FlowLayout.LEFT)); 582 582 promptInnerPanelA [i]= new JPanel(); 583 583 promptInnerPanelA[i].setBorder(BorderFactory.createLineBorder (voxforgeColour, 1)); 584 //promptInnerPanelA[i].add(new MultiLineLabel(promptPanelA[i], i+":"+this.promptA[i], maxWidth)); 584 585 promptInnerPanelA[i].add(new MultiLineLabel(promptPanelA[i], this.promptA[i], maxWidth)); 585 586 promptPanelA[i].add(promptInnerPanelA[i]); 586 587 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 } 588 593 prompts.add(promptPanelA[i]); 589 594 } … … 799 804 b.addActionListener(this); 800 805 p.add(b); 806 // !!!!!! 807 b.setEnabled(state); 808 // !!!!!! 801 809 return b; 802 810 } … … 807 815 playA[i].setEnabled(false); 808 816 captA[i].setEnabled(false); 817 //System.err.println("setButtonsOff" + "playA" + i + playA[i].isEnabled()+ ";captA" + i + captA[i].isEnabled());// !!!!!! 809 818 } 810 819 /* … … 835 844 // !!!!!! 836 845 for (int i = 0; i < numberofPrompts; i++) { 837 playA[i].setEnabled(false);838 846 if (playA[i].isEnabled()) {play_stateA [i] = true;} else {play_stateA [i] = false;} 839 847 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());// !!!!!! 840 849 } 841 850 /* … … 866 875 // !!!!!! 867 876 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);} 870 878 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());// !!!!!! 871 880 } 872 881 /* … … 893 902 !!!!!! */ 894 903 } 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 // !!!!!! 896 914 public void actionPerformed(ActionEvent e) { 897 915 Object obj = e.getSource(); … … 899 917 // ################### Play ####################################### 900 918 // !!!!!! 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); 922 982 } 923 983 } 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 /* 960 987 if (obj.equals(play1)) { 961 988 if (play1.getText().startsWith(playButton)) { … … 1442 1469 !!!!!! */ 1443 1470 // ################### Upload ####################################### 1444 else if (obj.equals(uploadB)) {1471 // else if (obj.equals(uploadB)) { 1445 1472 //!!!!!! 1473 if (obj.equals(uploadB)) { 1446 1474 for (int i = 0; i < numberofPrompts; i++) { 1447 1475 playA[i].setEnabled(false); … … 1724 1752 } 1725 1753 outbaos.write(data, 0, numBytesRead); 1726 // !!!!!!1727 1754 /// System.err.println("numBytesRead" + numBytesRead); 1728 // !!!!!!1729 1755 } catch (Exception e) { 1730 1756 shutDown("Error during playback: " + e); … … 1733 1759 } 1734 1760 byte audioBytes[] = outbaos.toByteArray(); 1735 // !!!!!!1736 1761 // debug System.err.println("outbaos size:" + outbaos.size()); 1737 1762 outbaos.reset(); 1738 1763 outbaos = null; 1739 // !!!!!!1740 1764 samplingGraph.createWaveForm(audioBytes); 1741 1765 samplingGraph.repaint(); … … 1772 1796 1773 1797 shutDown(null); 1798 // !!!!! 1799 restoreButtonState(); 1800 // !!!!!! 1774 1801 } 1775 1802 } // End class Playback