Ignore:
Timestamp:
10/02/19 14:19:48 (5 years ago)
Author:
bln4
Message:

Implementation of ProfileManager. Refactor + additional content for how new profiles are created. The refactoring split out the creation of the default profile from user profiles. Refactoring revealed a long term bug that was causing user profiles to generate with incorrect information. The additional content fixed this bug by introducing the ${USER.NAME} variable, so that the default profile frameset can specify resource locations located in the users resource directory.

org.expeditee.auth.AuthenticatorBrowser
org.expeditee.auth.account.Create
org.expeditee.gui.Browser
org.expeditee.gui.management.ProfileManager
org.expeditee.setting.DirectoryListSetting
org.expeditee.setting.ListSetting
org.expeditee.settings.UserSettings

Implementation of ResourceManager as a core location to get resources from the file system. Also the additional variable ${CURRENT_FRAMESET} to represent the current frameset, so that images can be stored in the directory of the current frameset. This increases portability of framesets.

org.expeditee.gui.FrameIO
org.expeditee.gui.management.ResourceManager
org.expeditee.gui.management.ResourceUtil
Audio:

#NB: Audio used to only operate on a single directory. This has been updated to work in a same way as images. That is: when you ask for a specific resouce, it looks to the user settings to find a sequence of directories to look at in order until it manages to find the desired resource.


There is still need however for a single(ish) source of truth for the .banks and .mastermix file. Therefore these files are now always located in resource-<username>\audio.
org.apollo.agents.MelodySearch
org.apollo.audio.structure.AudioStructureModel
org.apollo.audio.util.MultiTrackPlaybackController
org.apollo.audio.util.SoundDesk
org.apollo.gui.FrameLayoutDaemon
org.apollo.io.AudioPathManager
org.apollo.util.AudioPurger
org.apollo.widgets.FramePlayer
org.apollo.widgets.SampledTrack

Images:

org.expeditee.items.ItemUtils

Frames:

org.expeditee.gui.FrameIO

Fixed a error in the FramePlayer class caused by an incorrect use of toArray().

org.apollo.widgets.FramePlayer


Added several short cut keys to allow for the Play/Pause (Ctrl + P), mute (Ctrl + M) and volume up/down (Ctrl + +/-) when hovering over SampledTrack widgets.

org.apollo.widgets.SampledTrack


Changed the way that Authenticate.login parses the new users profile to be more consistance with other similar places in code.

org.expeditee.auth.account.Authenticate


Encapsulated _body, _surrogateItemsBody and _primaryItemsBody in Frame class. Also changed getBody function to take a boolean flag as to if it should respect the current surrogate mode. If it should then it makes sure that labels have not changed since last time getBody was called.

org.expeditee.gui.Frame

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/io/AudioPathManager.java

    r1327 r1434  
    77import java.io.IOException;
    88import java.io.UnsupportedEncodingException;
     9import java.util.ArrayList;
     10import java.util.List;
    911import java.util.Random;
     12import java.util.function.Predicate;
    1013
    1114import org.apollo.audio.structure.AudioStructureModel;
    1215import org.apollo.util.ApolloSystemLog;
    1316import org.apollo.util.RegExpFileFilter;
    14 import org.expeditee.auth.AuthenticatorBrowser;
     17import org.expeditee.gui.DisplayController;
    1518import org.expeditee.gui.FrameIO;
     19import org.expeditee.gui.management.ResourceManager;
    1620import org.expeditee.settings.UserSettings;
    1721
     
    2933
    3034        /** Suffixed with the native file separator */
    31         public static String AUDIO_HOME_DIRECTORY = null;
     35        public static String AUDIO_USERNAME_HOME_DIRECTORY = null;
    3236       
    3337        /** Stores all virtual names created by this repository. */
     
    3943
    4044        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               
    7951                // Load counter
    80                 loadCounter(AUDIO_HOME_DIRECTORY);
    81         }
    82        
     52                loadCounter();
     53        }
    8354       
    8455        /**
    8556         * 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               
    9661                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                }
    12486                counter = count;
    125         }
    126        
    127         /**
    128          * @param dir
    129          * @return
    130          *              Null if an IO exception occurs
    131          */
    132         private static String[] getAudioFileNames(File dir) {
    133                 return dir.list(new RegExpFileFilter("^[A-Z]+\\d+.*$"));
    13487        }
    13588       
     
    14093         *              read list of files.
    14194         */
    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;
    146117        }
    147118       
     
    168139                String filename = generateRandomFilenameBase() + "." + extension;
    169140               
    170                 File f = new File(AUDIO_HOME_DIRECTORY + filename);
     141                File f = new File(AUDIO_USERNAME_HOME_DIRECTORY + filename);
    171142
    172143                if (AudioStructureModel.getInstance().getTrackGraphInfo(filename, null) != null ||
     
    206177
    207178                // Build the filename string
    208                 return preamble + counter;
     179                return UserSettings.UserName.get() + preamble + counter;
    209180               
    210181        }
     
    222193
    223194                // 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);
    225196                if (!vnameBase.exists()) {
    226197                        try {
Note: See TracChangeset for help on using the changeset viewer.