예제 #1
0
        private bool loadFile(string filepath,
                              Color foreground,
                              Color background)
        {
            if (filepath == null || filepath.EndsWith("~") || !File.Exists(filepath))
            {
                return(false);
            }

            showShadowBox("Loading '" + filepath + "'");

            bool loaded = false;

            SSI_FILE_TYPE ftype = SSI_FILE_TYPE.UNKOWN;

            int index = filepath.LastIndexOf('.');

            if (index > 0)
            {
                string type = filepath.Substring(index + 1).ToLower();
                switch (type)
                {
                case "avi":
                case "wmv":
                case "mp4":
                case "mov":
                case "m4a":
                case "mkv":
                case "divx":
                case "mpg":
                case "PNG":
                case "jpg":
                case "png":
                case "jpeg":
                case "gif":
                case "webm":

                    ftype = SSI_FILE_TYPE.VIDEO;
                    Time.TotalDuration = 1;     // This allows to annotate images
                    break;

                case "csv":
                case "anno":
                    ftype = SSI_FILE_TYPE.CSV;
                    break;

                case "wma":
                case "wav":
                case "mp3":
                case "flac":
                    ftype = SSI_FILE_TYPE.AUDIO;
                    break;

                case "annotation":
                    ftype = SSI_FILE_TYPE.ANNOTATION;
                    break;

                case "stream":
                    ftype = SSI_FILE_TYPE.STREAM;
                    break;

                case "events":
                    ftype = SSI_FILE_TYPE.EVENTS;
                    break;

                case "eaf":
                    ftype = SSI_FILE_TYPE.EAF;
                    break;

                case "arff":
                    ftype = SSI_FILE_TYPE.ARFF;
                    break;

                case "anvil":
                    ftype = SSI_FILE_TYPE.ANVIL;
                    break;

                case "nova":
                    ftype = SSI_FILE_TYPE.PROJECT;
                    break;
                }
            }

            switch (ftype)
            {
            case SSI_FILE_TYPE.VIDEO:
                loadMediaFile(filepath, MediaType.VIDEO);
                loaded = true;
                break;

            case SSI_FILE_TYPE.AUDIO:

                string type   = filepath.Substring(index + 1);
                Signal signal = null;
                loadAudioSignalFile(filepath, foreground, background);

                IMedia media = loadMediaFile(filepath, MediaType.AUDIO);
                if (signal != null)
                {
                    signal.Media = media;
                }
                loaded = true;
                break;

            case SSI_FILE_TYPE.ANNOTATION:
                loadAnnoFile(filepath);
                loaded = true;
                break;

            case SSI_FILE_TYPE.STREAM:
                loadSignalFile(filepath, foreground, background);
                loaded = true;
                break;

            case SSI_FILE_TYPE.EVENTS:
                ImportAnnoFromSSIEvents(filepath);
                loaded = true;
                break;

            case SSI_FILE_TYPE.CSV:
                loadCSVFile(filepath, foreground, background);
                loaded = true;
                break;

            case SSI_FILE_TYPE.EAF:
                ImportAnnoFromElan(filepath);
                loaded = true;
                break;

            case SSI_FILE_TYPE.ARFF:
                loadARFFAnnoFile(filepath);
                loaded = true;
                break;

            case SSI_FILE_TYPE.ANVIL:
                ImportAnnoFromAnvil(filepath);
                loaded = true;
                break;

            case SSI_FILE_TYPE.PROJECT:
                loadProjectFile(filepath);
                loaded = true;
                // workaround
                foreach (AnnoList annoList in annoLists)
                {
                    annoList.HasChanged = false;
                }
                break;

            default:
                break;
            }

            hideShadowBox();

            return(loaded);
        }
예제 #2
0
        private bool loadFileHandler(string filename, string url = null)
        {
            if (filename == null || filename.EndsWith("~"))
            {
                return(false);
            }

            control.Cursor = Cursors.Wait;
            Action EmptyDelegate = delegate() { };

            control.ShadowBoxText.Text   = "Loading '" + filename + "'";
            control.ShadowBox.Visibility = Visibility.Visible;
            control.UpdateLayout();
            control.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

            bool loaded = false;

            SSI_FILE_TYPE ftype = SSI_FILE_TYPE.UNKOWN;

            int index = filename.LastIndexOf('.');

            if (index > 0)
            {
                string type = filename.Substring(index + 1);
                switch (type)
                {
                case "avi":
                case "wmv":
                case "mp4":
                case "mov":
                case "MOV":
                case "m4a":
                case "mkv":
                case "divx":
                case "mpg":
                case "JPG":
                case "JPEG":
                case "PNG":
                case "jpg":
                case "png":
                case "jpeg":
                case "gif":
                case "webm":

                    ftype = SSI_FILE_TYPE.VIDEO;
                    break;

                case "csv":
                case "anno":
                    ftype = SSI_FILE_TYPE.CSV;
                    break;

                case "wav":
                    ftype = SSI_FILE_TYPE.AUDIO;
                    break;

                case "annotation":
                    ftype = SSI_FILE_TYPE.ANNOTATION;
                    break;

                case "stream":
                    ftype = SSI_FILE_TYPE.STREAM;
                    break;

                case "events":
                    ftype = SSI_FILE_TYPE.EVENTS;
                    break;

                case "eaf":
                    ftype = SSI_FILE_TYPE.EAF;
                    break;

                case "arff":
                    ftype = SSI_FILE_TYPE.ARFF;
                    break;

                case "anvil":
                    ftype = SSI_FILE_TYPE.ANVIL;
                    break;

                case "nova":
                    ftype = SSI_FILE_TYPE.PROJECT;
                    break;
                }
            }

            switch (ftype)
            {
            case SSI_FILE_TYPE.VIDEO:
                loadMedia(filename, true, url);
                this.vfilename = Path.GetFileNameWithoutExtension(filename);
                loaded         = true;
                break;

            case SSI_FILE_TYPE.CSV:

                //Read first line, check if format is an annotation, else interpret it as external csv
                //Read second line to check for sample rate (only relevant for continous files)
                string csvanno    = "^([0-9]+.[0-9]+|[0-9]+);([0-9]+.[0-9]+|[0-9]+);.*";
                string legacyanno = "^([0-9]+.[0-9]+|[0-9]+) ([0-9]+.[0-9]+|[0-9]+) .*";
                string csvcont    = "^([0-9]+.[0-9]+|[0-9]+;)(.)[^;]*";
                string csvcontnew = "^((-?)[0-9]+.[0-9]+|[0-9]+;)+([0-9]+|[0-9]+;)(.)[^;];\\#.*";

                string type = "";

                Regex        reg        = new Regex(csvanno);
                Regex        reglegacy  = new Regex(legacyanno);
                Regex        regcont    = new Regex(csvcont);
                Regex        regcontnew = new Regex(csvcontnew);
                StreamReader sr         = new StreamReader(filename, System.Text.Encoding.Default);
                string       line       = sr.ReadLine();
                double       samplerate = 1.0;

                if (line != null)
                {
                    bool iscontinouswithtier = regcontnew.IsMatch(line);
                    if (reg.IsMatch(line) && !iscontinouswithtier)
                    {
                        type = "semicolon";
                    }
                    else if (reglegacy.IsMatch(line) && !iscontinouswithtier)
                    {
                        type = "legacy";
                    }
                    else if ((regcont.IsMatch(line) || iscontinouswithtier))
                    {
                        string[] data = line.Split(';');
                        try
                        {
                            double start = Convert.ToDouble(data[0], CultureInfo.InvariantCulture);
                            line = sr.ReadLine();
                            data = line.Split(';');
                            double start2 = Convert.ToDouble(data[0], CultureInfo.InvariantCulture);
                            samplerate = start2 - start;
                            type       = "continuous";
                        }
                        catch
                        {
                            MessageBox.Show("Error reading continuous file");
                        }
                    }

                    sr.Close();
                }
                else
                {
                    type = "semicolon";
                }

                if (type == "continuous" || type == "semicolon" || type == "legacy")
                {
                    loadCSVAnnotation(filename, samplerate, type);
                }
                else
                {
                    loadCSV(filename);
                }

                loaded = true;
                break;

            case SSI_FILE_TYPE.AUDIO:
                loadWav(filename);
                loadMedia(filename, false);
                loaded = true;
                break;

            case SSI_FILE_TYPE.ANNOTATION:
                loadAnnotation(filename);
                loaded = true;

                break;

            case SSI_FILE_TYPE.STREAM:
                loadStream(filename);
                loaded = true;
                break;

            case SSI_FILE_TYPE.EVENTS:
                ImportAnnoFromSSIEvents(filename);
                loaded = true;
                break;

            case SSI_FILE_TYPE.EAF:
                ImportAnnoFromElan(filename);
                loaded = true;
                break;

            case SSI_FILE_TYPE.ARFF:
                loadARFF(filename);
                loaded = true;
                break;

            case SSI_FILE_TYPE.ANVIL:
                ImportAnnoFromAnvil(filename);
                loaded = true;
                break;

            case SSI_FILE_TYPE.PROJECT:
                loadProject(filename);
                loaded = true;
                break;

            default:
                break;
            }

            control.ShadowBox.Visibility = Visibility.Collapsed;
            control.Cursor = Cursors.Arrow;

            return(loaded);
        }