Changeset 1434 for trunk/src/org/apollo
- Timestamp:
- 10/02/19 14:19:48 (5 years ago)
- Location:
- trunk/src/org/apollo
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/agents/MelodySearch.java
r1244 r1434 11 11 12 12 import org.apollo.ApolloSystem; 13 import org.apollo.io.AudioPathManager;14 13 import org.apollo.meldex.DynamicProgrammingAlgorithm; 15 14 import org.apollo.meldex.McNabMongeauSankoffAlgorithm; … … 28 27 import org.expeditee.gui.Frame; 29 28 import org.expeditee.gui.FrameIO; 30 import org.expeditee. settings.folders.FolderSettings;29 import org.expeditee.gui.management.ResourceManager; 31 30 import org.expeditee.items.Item; 32 31 import org.expeditee.items.ItemUtils; … … 34 33 import org.expeditee.items.widgets.WidgetCorner; 35 34 import org.expeditee.items.widgets.WidgetEdge; 35 import org.expeditee.settings.folders.FolderSettings; 36 36 37 37 /** … … 278 278 279 279 // Get cached melody from file if it is up to date 280 String metaFilePath = 281 AudioPathManager.AUDIO_HOME_DIRECTORY 282 + MELODY_METAFILE_PREFIX 283 + localFilename 284 + MELODY_METAFILE_SUFFIX; 285 286 File localFile = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + localFilename); 280 String metaFileRelativePath = MELODY_METAFILE_PREFIX + localFilename + MELODY_METAFILE_SUFFIX; 281 String metaFilePath = ResourceManager.getAudioResource(metaFileRelativePath, DisplayController.getCurrentFrame()).getAbsolutePath(); 282 283 //File localFile = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + localFilename); 284 File localFile = ResourceManager.getAudioResource(localFilename, DisplayController.getCurrentFrame()); 287 285 if (!localFile.exists()) continue; 288 286 -
trunk/src/org/apollo/audio/structure/AudioStructureModel.java
r1244 r1434 16 16 import org.apollo.audio.ApolloSubjectChangedEvent; 17 17 import org.apollo.io.AudioIO; 18 import org.apollo.io.AudioPathManager;19 18 import org.apollo.mvc.AbstractSubject; 20 19 import org.apollo.mvc.SubjectChangedEvent; … … 30 29 import org.expeditee.gui.Frame; 31 30 import org.expeditee.gui.FrameIO; 31 import org.expeditee.gui.management.ResourceManager; 32 32 import org.expeditee.io.Conversion; 33 33 import org.expeditee.items.ItemUtils; … … 433 433 try { 434 434 435 tmodel.runningTimeMS = AudioIO.getRunningTime(AudioPathManager.AUDIO_HOME_DIRECTORY + localFilename); 435 String localFilePath = ResourceManager.getAudioResource(localFilename, DisplayController.getCurrentFrame()).getAbsolutePath(); 436 tmodel.runningTimeMS = AudioIO.getRunningTime(localFilePath); 436 437 437 438 } catch (IOException e) { -
trunk/src/org/apollo/audio/util/MultiTrackPlaybackController.java
r1102 r1434 20 20 import org.apollo.audio.structure.TrackGraphLoopException; 21 21 import org.apollo.audio.structure.TrackGraphNode; 22 import org.apollo.io.AudioPathManager;23 22 import org.apollo.io.AudioIO.AudioFileLoader; 24 23 import org.apollo.mvc.AbstractSubject; … … 34 33 import org.expeditee.gui.DisplayController; 35 34 import org.expeditee.gui.DisplayObserver; 35 import org.expeditee.gui.management.ResourceManager; 36 36 37 37 public class MultiTrackPlaybackController … … 1004 1004 1005 1005 try { 1006 String filepath = ResourceManager.getAudioResource(absNode.getTrackNode().getLocalFilename(), DisplayController.getCurrentFrame()).getAbsolutePath(); 1006 1007 stm = TrackModelLoadManager.getInstance().load( 1007 AudioPathManager.AUDIO_HOME_DIRECTORY + absNode.getTrackNode().getLocalFilename(),1008 filepath, 1008 1009 absNode.getTrackNode().getLocalFilename(), 1009 1010 new Observer() { // opps, my confusing design pattern gone wrong! -
trunk/src/org/apollo/audio/util/SoundDesk.java
r375 r1434 71 71 72 72 /** Where the mixes are saved to. */ 73 private static final String MIX_BANKS_FILEPATH = AudioPathManager.AUDIO_ HOME_DIRECTORY + ".banks";74 75 private static final String MASTER_MIX_FILEPATH = AudioPathManager.AUDIO_ HOME_DIRECTORY + ".mastermix";73 private static final String MIX_BANKS_FILEPATH = AudioPathManager.AUDIO_USERNAME_HOME_DIRECTORY + ".banks"; 74 75 private static final String MASTER_MIX_FILEPATH = AudioPathManager.AUDIO_USERNAME_HOME_DIRECTORY + ".mastermix"; 76 76 77 77 private static final String NO_SOLO_PREFIX = "~#SOLOOFF#~"; -
trunk/src/org/apollo/gui/FrameLayoutDaemon.java
r1258 r1434 15 15 import org.apollo.audio.util.Timeline; 16 16 import org.apollo.io.AudioIO; 17 import org.apollo.io.AudioPathManager;18 17 import org.apollo.mvc.AbstractSubject; 19 18 import org.apollo.mvc.Observer; … … 32 31 import org.expeditee.gui.Frame; 33 32 import org.expeditee.gui.FreeItems; 33 import org.expeditee.gui.management.ResourceManager; 34 34 import org.expeditee.items.Item; 35 35 import org.expeditee.items.ItemUtils; … … 766 766 // so cann afford to hang the thread a little for checking the actual time... 767 767 if (runningTime <= 0) { 768 File f = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + 769 sampledTrackWidget.getLocalFileName()); 768 //File f = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + 769 // sampledTrackWidget.getLocalFileName()); 770 File f = ResourceManager.getAudioResource(sampledTrackWidget.getLocalFileName(), DisplayController.getCurrentFrame()); 770 771 if (f.exists()) { 771 772 try { -
trunk/src/org/apollo/io/AudioPathManager.java
r1327 r1434 7 7 import java.io.IOException; 8 8 import java.io.UnsupportedEncodingException; 9 import java.util.ArrayList; 10 import java.util.List; 9 11 import java.util.Random; 12 import java.util.function.Predicate; 10 13 11 14 import org.apollo.audio.structure.AudioStructureModel; 12 15 import org.apollo.util.ApolloSystemLog; 13 16 import org.apollo.util.RegExpFileFilter; 14 import org.expeditee. auth.AuthenticatorBrowser;17 import org.expeditee.gui.DisplayController; 15 18 import org.expeditee.gui.FrameIO; 19 import org.expeditee.gui.management.ResourceManager; 16 20 import org.expeditee.settings.UserSettings; 17 21 … … 29 33 30 34 /** Suffixed with the native file separator */ 31 public static String AUDIO_ HOME_DIRECTORY = null;35 public static String AUDIO_USERNAME_HOME_DIRECTORY = null; 32 36 33 37 /** Stores all virtual names created by this repository. */ … … 39 43 40 44 private static Random rand = new Random(System.currentTimeMillis()); 41 42 // **** DB 43 // Some work to be done here => remove dependency in code on 'AUDIO_HOME_DIRECTORY' 44 // and change it to use audio dir list from UserSettings 45 public static void changeParentAndSubFolders(String newFolder) { 46 47 if (AuthenticatorBrowser.isAuthenticationRequired() && System.getProperty("user.name").equals(AuthenticatorBrowser.USER_NOBODY)) { 48 System.err.println("**** AudioPathManager::changeParentAndSubFolder(): Nothing to do for user '" + AuthenticatorBrowser.USER_NOBODY + "'"); 49 return; 50 } 51 52 if (UserSettings.PublicAndPrivateResources) { 53 //String resourcesPublicPath = FrameIO.PARENT_FOLDER + "resources-public" + File.separator; 54 String userName = UserSettings.UserName.get(); 55 //String resourcesPrivateIndividualPath = FrameIO.PARENT_FOLDER + "resources-" + userName + File.separator; 56 if (AuthenticatorBrowser.isAuthenticationRequired()) { 57 System.err.println("**** AudioPathManager::changeParentAndSubFolder(): Setting 'audio' folder to resources-" + userName); 58 } 59 //AUDIO_HOME_DIRECTORY = resourcesPrivateIndividualPath + "audio" + File.separatorChar; 60 AUDIO_HOME_DIRECTORY = FrameIO.AUDIO_PRIVATE_PATH; 61 } 62 else { 63 AUDIO_HOME_DIRECTORY = FrameIO.PARENT_FOLDER + "audio" + File.separatorChar;; 64 } 65 } 66 67 public static void activateAndScanAudioDir() 68 { 69 changeParentAndSubFolders(FrameIO.PARENT_FOLDER); 70 71 // Ensure audio directory exists 72 File dir = new File(AUDIO_HOME_DIRECTORY); 73 if (!dir.exists()) { 74 if (!dir.mkdir()) { 75 ApolloSystemLog.println("Unable to create missing audio home directory"); 76 } 77 } 78 45 46 // TODO: this function called during startup? In browser construction? When FrameIO.changeParentAndSubFolders() is called? Separation of apollo from expeditee core? 47 public static void activateAndScanAudioDirs() { 48 // If we are in old regime then there is no AUDIO_USERNAME_PRIVATE_PATH. 49 AUDIO_USERNAME_HOME_DIRECTORY = FrameIO.AUDIO_USERNAME_PRIVATE_PATH == null ? FrameIO.AUDIO_PATH : FrameIO.AUDIO_USERNAME_PRIVATE_PATH; 50 79 51 // Load counter 80 loadCounter(AUDIO_HOME_DIRECTORY); 81 } 82 52 loadCounter(); 53 } 83 54 84 55 /** 85 56 * Loads the counter 86 * @param dir The dir where the audio files live. 87 */ 88 private static void loadCounter(String audio_dir_str) { 89 File audio_dir = new File(audio_dir_str); 90 91 String[] files = getAudioFileNames(audio_dir); 92 if (files == null) { // Due to IO exception 93 ApolloSystemLog.printError("Failed to read audio directory"); 94 return; 95 } 57 */ 58 private static void loadCounter() { 59 List<String> audioFileNames = getAudioFileNames(); 60 96 61 long count = 0; 97 if (files != null) { 98 for (String f : files) { 99 100 int start = -1, end = -1; 101 for (int i = 0; i < f.length(); i++) { 102 if (Character.isDigit(f.charAt(i)) && start == -1) { 103 start = i; 104 } else if (!Character.isDigit(f.charAt(i)) && start != -1) { 105 end = i; 106 break; 107 } 108 } 109 110 if (start >= 0 && end == -1) { 111 end = f.length(); 112 } 113 114 if (start > 0 && end >= start) { // not start >= 0 since missing preable 115 116 String tmp = f.substring(start, end); 117 long l = Long.parseLong(tmp); 118 if (l >= count) 119 count = l + 1; 120 } 121 } 122 } 123 62 for (String f : audioFileNames) { 63 64 int start = -1, end = -1; 65 for (int i = 0; i < f.length(); i++) { 66 if (Character.isDigit(f.charAt(i)) && start == -1) { 67 start = i; 68 } else if (!Character.isDigit(f.charAt(i)) && start != -1) { 69 end = i; 70 break; 71 } 72 } 73 74 if (start >= 0 && end == -1) { 75 end = f.length(); 76 } 77 78 if (start > 0 && end >= start) { // not start >= 0 since missing preable 79 80 String tmp = f.substring(start, end); 81 long l = Long.parseLong(tmp); 82 if (l >= count) 83 count = l + 1; 84 } 85 } 124 86 counter = count; 125 }126 127 /**128 * @param dir129 * @return130 * Null if an IO exception occurs131 */132 private static String[] getAudioFileNames(File dir) {133 return dir.list(new RegExpFileFilter("^[A-Z]+\\d+.*$"));134 87 } 135 88 … … 140 93 * read list of files. 141 94 */ 142 public static String[] getAudioFileNames() { 143 File audioDir = new File(AUDIO_HOME_DIRECTORY); 144 if (!audioDir.exists() || !audioDir.isDirectory()) return null; 145 return getAudioFileNames(audioDir); 95 public static List<String> getAudioFileNames() { 96 Predicate<File> isFile = file -> { 97 File dirForFile = file.toPath().getParent().toFile(); 98 if (!dirForFile.exists()) { 99 if (!dirForFile.mkdir()) { 100 ApolloSystemLog.println("Unable to create missing audio directory: " + dirForFile.toString()); 101 } 102 } 103 if (file.isFile()) { 104 return true; 105 } 106 return false; 107 }; 108 List<File> allFilesInAudioDirectories = ResourceManager.gatherAudioResources(isFile, DisplayController.getCurrentFrame()); 109 List<String> audioFileNames = new ArrayList<String>(); 110 RegExpFileFilter regExpFileFilter = new RegExpFileFilter("^[A-Z]+\\d+.*$"); 111 for (File file: allFilesInAudioDirectories) { 112 if (regExpFileFilter.accept(file, file.getAbsolutePath())) { 113 audioFileNames.add(file.getName()); 114 } 115 } 116 return audioFileNames; 146 117 } 147 118 … … 168 139 String filename = generateRandomFilenameBase() + "." + extension; 169 140 170 File f = new File(AUDIO_ HOME_DIRECTORY + filename);141 File f = new File(AUDIO_USERNAME_HOME_DIRECTORY + filename); 171 142 172 143 if (AudioStructureModel.getInstance().getTrackGraphInfo(filename, null) != null || … … 206 177 207 178 // Build the filename string 208 return preamble + counter;179 return UserSettings.UserName.get() + preamble + counter; 209 180 210 181 } … … 222 193 223 194 // Ensure that the name base file exists. Assumes the audio home directory exists. 224 File vnameBase = new File(AUDIO_ HOME_DIRECTORY + VIRTUAL_NAME_BASEFILE);195 File vnameBase = new File(AUDIO_USERNAME_HOME_DIRECTORY + VIRTUAL_NAME_BASEFILE); 225 196 if (!vnameBase.exists()) { 226 197 try { -
trunk/src/org/apollo/util/AudioPurger.java
r1244 r1434 11 11 import org.apollo.widgets.SampledTrack; 12 12 import org.expeditee.settings.folders.FolderSettings; 13 import org.expeditee.gui.DisplayController; 14 import org.expeditee.gui.management.ResourceManager; 13 15 import org.expeditee.items.ItemUtils; 14 16 … … 26 28 public static void purgeLocalAudio() { 27 29 28 String[]audioFiles = AudioPathManager.getAudioFileNames();29 if (audioFiles == null || audioFiles. length== 0) return;30 List<String> audioFiles = AudioPathManager.getAudioFileNames(); 31 if (audioFiles == null || audioFiles.size() == 0) return; 30 32 31 33 … … 50 52 for (String audioFile : audioFiles) { 51 53 if (!referencedAudio.contains(audioFile)) { 52 53 File unreferencedFile = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + audioFile);54 File unreferencedFile = ResourceManager.getAudioResource(audioFile, DisplayController.getCurrentFrame()); 55 //File unreferencedFile = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + audioFile); 54 56 ApolloSystemLog.println("Deleting unreference audio file \"" + audioFile + "\""); 55 57 unreferencedFile.delete(); 56 58 57 59 // Also delete any melody meta 58 File melodyMetaFile = new File( 59 AudioPathManager.AUDIO_HOME_DIRECTORY + 60 MelodySearch.MELODY_METAFILE_PREFIX + 61 audioFile + 62 MelodySearch.MELODY_METAFILE_SUFFIX); 60 String melodyFileName = MelodySearch.MELODY_METAFILE_PREFIX + audioFile + MelodySearch.MELODY_METAFILE_SUFFIX; 61 File melodyMetaFile = ResourceManager.getAudioResource(melodyFileName, DisplayController.getCurrentFrame()); 63 62 64 63 if (melodyMetaFile.exists()) melodyMetaFile.delete(); -
trunk/src/org/apollo/widgets/FramePlayer.java
r1102 r1434 107 107 108 108 // Read typed frames 109 File f = new File(AudioPathManager.AUDIO_ HOME_DIRECTORY + TYPED_FRAMED_HISTORY_FILE);109 File f = new File(AudioPathManager.AUDIO_USERNAME_HOME_DIRECTORY + TYPED_FRAMED_HISTORY_FILE); 110 110 if (f.exists()) { 111 111 BufferedReader in = null; … … 147 147 try { 148 148 // Open the vbase for appending 149 out = new FileWriter(AudioPathManager.AUDIO_ HOME_DIRECTORY + TYPED_FRAMED_HISTORY_FILE, false);149 out = new FileWriter(AudioPathManager.AUDIO_USERNAME_HOME_DIRECTORY + TYPED_FRAMED_HISTORY_FILE, false); 150 150 for (String str : typedFrameNames) { 151 151 out.write(str + "\n"); … … 802 802 } 803 803 804 ComboBoxModel<String> model = new DefaultComboBoxModel<String>((String[]) orderedModelData.toArray()); 804 ComboBoxModel<String> model = new DefaultComboBoxModel<String>((String[]) orderedModelData.toArray(new String[] {})); 805 //ComboBoxModel model = new DefaultComboBoxModel(orderedModelData.toArray()); 805 806 806 807 // Remove helper tags from model data -
trunk/src/org/apollo/widgets/SampledTrack.java
r1179 r1434 23 23 import javax.sound.sampled.LineUnavailableException; 24 24 import javax.sound.sampled.UnsupportedAudioFileException; 25 import javax.swing.JSlider; 25 26 import javax.swing.SwingUtilities; 26 27 … … 70 71 import org.expeditee.gui.FrameIO; 71 72 import org.expeditee.gui.PopupManager; 73 import org.expeditee.gui.management.ResourceManager; 72 74 import org.expeditee.items.ItemParentStateChangedEvent; 73 75 import org.expeditee.items.ItemUtils; … … 401 403 402 404 }); 403 405 404 406 fulltrackView.addKeyListener(new KeyListener() { 405 407 406 408 @Override 407 public void keyPressed(KeyEvent e) 408 { 409 public void keyPressed(KeyEvent e) { 409 410 } 410 411 411 412 @Override 412 public void keyReleased(KeyEvent e) 413 { 413 public void keyReleased(KeyEvent e) { 414 415 // On 26th September, Bryce added P M + - keys to play/pause/resume, mute and adjust volume. 416 if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_P) { 417 try { 418 playbackControlPopup.playPauseResume(); 419 } catch (LineUnavailableException e1) { 420 e1.printStackTrace(); 421 } 422 } else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_M) { 423 boolean selected = playbackControlPopup.muteButton.isSelected(); 424 playbackControlPopup.muteButton.setSelected(!selected); 425 playbackControlPopup.muteChanged(); 426 } else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_SUBTRACT) { 427 JSlider volumeSlider = playbackControlPopup.volumeSlider; 428 int delta = Math.round(((float) (volumeSlider.getMaximum() - volumeSlider.getMinimum())) / 10f); 429 int newVolume = Math.max(volumeSlider.getValue() - delta, volumeSlider.getMinimum()); 430 volumeSlider.setValue(newVolume); 431 playbackControlPopup.volumeChanged(); 432 } else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_ADD) { 433 JSlider volumeSlider = playbackControlPopup.volumeSlider; 434 int delta = Math.round(((float) (volumeSlider.getMaximum() - volumeSlider.getMinimum())) / 10f); 435 int newVolume = Math.min(volumeSlider.getValue() + delta, volumeSlider.getMaximum()); 436 volumeSlider.setValue(newVolume); 437 playbackControlPopup.volumeChanged(); 438 } 439 414 440 // Toggle pitch-track indexing 415 if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_I) {441 else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_I) { 416 442 setShouldOmitIndexAudio(!shouldOmitIndexAudio()); 417 443 DisplayController.requestRefresh(true); … … 765 791 setLoadScreenMessage("Loading audio file..."); 766 792 767 f = new File( 768 AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName); 793 //f = new File( 794 // AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName); 795 f = ResourceManager.getAudioResource(localFileName, getParentFrame()); 769 796 } 770 797 … … 809 836 // If recovering - might be recovering an existing track that had been 810 837 // saved to the repository .. thus re-use the old file 811 trackModel.setFilepath(AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName); 838 File audioResource = ResourceManager.getAudioResource(localFileName, getParentFrame()); 839 trackModel.setFilepath(audioResource.getAbsolutePath()); 812 840 } 813 841 … … 940 968 // If saving for the file time then get a filename 941 969 if (trackModel.getFilepath() == null) { 942 trackModel.setFilepath(AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName); 970 File audioResource = ResourceManager.getAudioResource(localFileName, DisplayController.getCurrentFrame()); 971 trackModel.setFilepath(audioResource.getAbsolutePath()); 943 972 loadFilenameArgument = localFileName; // set to now local, next load will be local 944 973 } … … 1029 1058 1030 1059 // Get rid of local file 1031 File oldLocalFile = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName); 1060 //File oldLocalFile = new File(AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName); 1061 File oldLocalFile = ResourceManager.getAudioResource(localFileName, getParentFrame()); 1032 1062 if (oldLocalFile.isFile() && oldLocalFile.exists()) { 1033 1063 try { … … 1157 1187 return recoveryFile.getAbsolutePath(); 1158 1188 } 1159 1160 return AudioPathManager.AUDIO_HOME_DIRECTORY + localFileName; 1189 1190 File audioResource = ResourceManager.getAudioResource(localFileName, getParentFrame()); 1191 return audioResource.getAbsolutePath(); 1161 1192 1162 1193 … … 2005 2036 try { 2006 2037 2007 if (!SoundDesk.getInstance().isPlaying(trackMix.getChannelID())) { // play / resume 2008 2009 int startFrame = -1, endFrame = -1; 2010 2011 // Resume playback? 2012 if (SoundDesk.getInstance().isPaused(trackMix.getChannelID())) { 2013 startFrame = SoundDesk.getInstance().getLastPlayedFramePosition(trackMix.getChannelID()); 2014 if (startFrame >= 0 && startFrame < trackModel.getFrameCount()) { 2015 2016 // The user may have edited the audio track and reselected it 2017 // since the last pause. Thus select an appropriate end frame 2018 endFrame = (trackModel.getSelectionLength() > 1) ? 2019 trackModel.getSelectionStart() + trackModel.getSelectionLength(): 2020 trackModel.getFrameCount() - 1; 2021 2022 // Changed selection? it play range invalid? 2023 if (endFrame <= startFrame || startFrame < trackModel.getSelectionStart()) { 2024 startFrame = -1; // Play new selection (see below) 2025 2026 } else if (endFrame >= trackModel.getFrameCount()) { 2027 endFrame = trackModel.getFrameCount() - 1; 2028 } 2029 2030 } 2031 } 2032 2033 // Play from beginning of selection to end of selection 2034 if (startFrame < 0) { 2035 startFrame = trackModel.getSelectionStart(); 2036 endFrame = (trackModel.getSelectionLength() > 1) ? 2037 startFrame + trackModel.getSelectionLength(): 2038 trackModel.getFrameCount() - 1; 2039 } 2040 2041 // Safety clamp: 2042 if (endFrame >= trackModel.getFrameCount()) { 2043 endFrame = trackModel.getFrameCount() - 1; 2044 } 2045 2046 if (startFrame < endFrame) { 2047 SoundDesk.getInstance().playSampledTrackModel( 2048 trackModel, 2049 trackMix.getChannelID(), 2050 startFrame, 2051 endFrame, 2052 0); 2053 } 2054 2055 } else { // pause 2056 2057 TrackSequence ts = SoundDesk.getInstance().getTrackSequence(trackMix.getChannelID()); 2058 2059 if (ts != null && 2060 ts.isPlaying()) { 2061 2062 // Mark channel as paused. 2063 SoundDesk.getInstance().setPaused(trackMix.getChannelID(), true); 2064 2065 // Stop playback for this channel 2066 ApolloPlaybackMixer.getInstance().stop(ts); 2067 2068 } 2069 2070 } 2038 playPauseResume(); 2071 2039 2072 2040 } catch (LineUnavailableException e1) { … … 2094 2062 } else if (e.getSource() == miscButton) { 2095 2063 expand(false); 2064 } 2065 } 2066 2067 private void playPauseResume() throws LineUnavailableException { 2068 if (!SoundDesk.getInstance().isPlaying(trackMix.getChannelID())) { // play / resume 2069 2070 int startFrame = -1, endFrame = -1; 2071 2072 // Resume playback? 2073 if (SoundDesk.getInstance().isPaused(trackMix.getChannelID())) { 2074 startFrame = SoundDesk.getInstance().getLastPlayedFramePosition(trackMix.getChannelID()); 2075 if (startFrame >= 0 && startFrame < trackModel.getFrameCount()) { 2076 2077 // The user may have edited the audio track and reselected it 2078 // since the last pause. Thus select an appropriate end frame 2079 endFrame = (trackModel.getSelectionLength() > 1) ? 2080 trackModel.getSelectionStart() + trackModel.getSelectionLength(): 2081 trackModel.getFrameCount() - 1; 2082 2083 // Changed selection? it play range invalid? 2084 if (endFrame <= startFrame || startFrame < trackModel.getSelectionStart()) { 2085 startFrame = -1; // Play new selection (see below) 2086 2087 } else if (endFrame >= trackModel.getFrameCount()) { 2088 endFrame = trackModel.getFrameCount() - 1; 2089 } 2090 2091 } 2092 } 2093 2094 // Play from beginning of selection to end of selection 2095 if (startFrame < 0) { 2096 startFrame = trackModel.getSelectionStart(); 2097 endFrame = (trackModel.getSelectionLength() > 1) ? 2098 startFrame + trackModel.getSelectionLength(): 2099 trackModel.getFrameCount() - 1; 2100 } 2101 2102 // Safety clamp: 2103 if (endFrame >= trackModel.getFrameCount()) { 2104 endFrame = trackModel.getFrameCount() - 1; 2105 } 2106 2107 if (startFrame < endFrame) { 2108 SoundDesk.getInstance().playSampledTrackModel( 2109 trackModel, 2110 trackMix.getChannelID(), 2111 startFrame, 2112 endFrame, 2113 0); 2114 } 2115 2116 } else { // pause 2117 2118 TrackSequence ts = SoundDesk.getInstance().getTrackSequence(trackMix.getChannelID()); 2119 2120 if (ts != null && 2121 ts.isPlaying()) { 2122 2123 // Mark channel as paused. 2124 SoundDesk.getInstance().setPaused(trackMix.getChannelID(), true); 2125 2126 // Stop playback for this channel 2127 ApolloPlaybackMixer.getInstance().stop(ts); 2128 2129 } 2130 2096 2131 } 2097 2132 }
Note:
See TracChangeset
for help on using the changeset viewer.