public override List<string> GetChildFiles(string file, FileTaskType taskType)
        {
            List<string> list = new List<string>();

            if (ProTONEConfig.UseLinkedFiles)
            {
                string fileType = PathUtils.GetExtension(file).ToUpperInvariant();
                string[] childFileTypes = ProTONEConfig.GetChildFileTypes(fileType);

                if (childFileTypes != null && childFileTypes.Length > 0)
                {
                    foreach (string childFileType in childFileTypes)
                    {
                        // This will find files like "FileName.PFT" and change them into "FileName.CFT"
                        string childFilePath = Path.ChangeExtension(file, childFileType);
                        if (File.Exists(childFilePath) && !list.Contains(childFilePath))
                        {
                            list.Add(childFilePath);
                        }

                        // This will find files like "FileName.PFT" and change them into "FileName.PFT.CFT"
                        // (i.e. handle double type extension case like for Bookmark files)
                        string childFileType2 = string.Format("{0}.{1}", PathUtils.GetExtension(file), childFileType);
                        string childFilePath2 = Path.ChangeExtension(file, childFileType2);
                        if (File.Exists(childFilePath2) && !list.Contains(childFilePath2))
                        {
                            list.Add(childFilePath2);
                        }
                    }
                }
            }

            return list;
        }
        public override string GetParentFile(string file, FileTaskType taskType)
        {
            if (ProTONEConfig.UseLinkedFiles)
            {
                string parentFilePath = "";

                if (Path.HasExtension(file))
                {
                    // Check whether the child file is a double extension file
                    // In this case the parent file should have same name but w/o the second extension part.
                    parentFilePath = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file));
                    if (File.Exists(parentFilePath))
                        return parentFilePath;
                }

                string fileType = Path.GetExtension(file).ToUpperInvariant();
                string[] parentFileTypes = ProTONEConfig.GetParentFileTypes(fileType);

                if (parentFileTypes != null && parentFileTypes.Length > 0)
                {
                    foreach (string parentFileType in parentFileTypes)
                    {
                        parentFilePath = Path.ChangeExtension(file, parentFileType);
                        if (File.Exists(parentFilePath))
                        {
                            return parentFilePath;
                        }
                    }
                }
            }

            return null;
        }
        public void DisplayFavorites()
        {
            lvFavorites.Items.Clear();
            _ilm.Clear();

            foreach (string path in ProTONEConfig.GetFavoriteFolders(FavoriteFoldersHiveName))
            {
                CreateItem(path);
            }
        }
Esempio n. 4
0
        private void OnBuildFavoritesMenu(object sender, EventArgs e)
        {
            try
            {
                ToolStripDropDownItem tsmi = sender as ToolStripDropDownItem;
                if (tsmi == null || tsmi.DropDownItems == null || tsmi.DropDownItems.Count < 2)
                {
                    return;
                }

                tsbFavorites.DropDown.BackColor = ThemeManager.WndValidColor;

                ilFavorites.Images.Clear();

                // Clear favorites items
                List <ToolStripItem> itemsToClear = new List <ToolStripItem>();
                foreach (ToolStripItem child in tsmi.DropDownItems)
                {
                    if ((child as ToolStripSeparator) != null || child.Tag != null)
                    {
                        continue;
                    }

                    itemsToClear.Add(child);
                }

                foreach (ToolStripItem itemToClear in itemsToClear)
                {
                    tsmi.DropDownItems.Remove(itemToClear);
                }

                List <string> favPaths = ProTONEConfig.GetFavoriteFolders("FavoriteFolders");
                if (favPaths != null && favPaths.Count > 0)
                {
                    foreach (string path in favPaths)
                    {
                        if (Directory.Exists(path))
                        {
                            OPMToolStripDropDownMenuItem tsi = new OPMToolStripDropDownMenuItem(tsbFavorites);
                            tsi.Text         = path;
                            tsi.Click       += new EventHandler(OnFavoriteChosen);
                            tsi.Image        = ilFavorites.Images[GetIcon(path)];
                            tsi.ImageScaling = ToolStripItemImageScaling.None;

                            tsmi.DropDownItems.Add(tsi);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
        private MediaRenderer(bool isDefaultInstance)
        {
            streamRenderer = null;

            SuiteRegistrationSupport.Init(GetSupportedFileProvider());

            timerCheckState          = new Timer();
            timerCheckState.Enabled  = true;
            timerCheckState.Interval = 500;
            timerCheckState.Start();
            timerCheckState.Tick += new EventHandler(timerCheckState_Tick);

            if (isDefaultInstance &&
                ProTONEConfig.IsPlayer &&
                ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.WCFInterface))
            {
                InternalInitSignalAnalisysWCF();
            }
        }
Esempio n. 6
0
        internal void SavePlaylist()
        {
            string filter = string.Empty;

            filter += MediaRenderer.DefaultInstance.PlaylistsFilter;
            filter += Translator.Translate("TXT_ALL_FILES_FILTER");
            filter  = filter.Replace("TXT_PLAYLISTS", Translator.Translate("TXT_PLAYLISTS"));

            OPMSaveFileDialog dlg = new OPMSaveFileDialog();

            dlg.Title            = Translator.Translate("TXT_SAVEPLAYLIST");
            dlg.Filter           = filter;
            dlg.DefaultExt       = "m3u";
            dlg.FilterIndex      = ProTONEConfig.PL_LastFilterIndex;
            dlg.InitialDirectory = ProTONEConfig.PL_LastOpenedFolder;

            dlg.InheritAppIcon = false;
            dlg.Icon           = OPMedia.UI.Properties.Resources.Save16.ToIcon();

            dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
            dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };
            dlg.ShowAddToFavorites      = true;

            dlg.ShowNewFolder = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                ProTONEConfig.PL_LastFilterIndex = dlg.FilterIndex;

                playlist.SavePlaylist(dlg.FileName);

                try
                {
                    string file = dlg.FileNames[0];
                    ProTONEConfig.PL_LastOpenedFolder = Path.GetDirectoryName(file);
                }
                catch
                {
                    ProTONEConfig.PL_LastOpenedFolder = dlg.InitialDirectory;
                }
            }
        }
        protected void SampleAnalyzerLoop()
        {
            while (sampleAnalyzerMustStop.WaitOne(0) == false)
            {
                if (ProTONEConfig.IsSignalAnalisysActive())
                {
                    AudioSample smp = null;
                    if (samples.TryDequeue(out smp) && smp != null)
                    {
                        ExtractSamples(smp);
                    }

                    Thread.Yield();
                }
                else
                {
                    Thread.Sleep(1);
                }
            }
        }
Esempio n. 8
0
        private void OpenCatalog()
        {
            tsbOpen.HideDropDown();

            OPMOpenFileDialog dlg = new OPMOpenFileDialog();

            dlg.Title            = Translator.Translate("TXT_OPENCATALOG");
            dlg.Filter           = Translator.Translate("TXT_CATALOG_FILTER");
            dlg.InitialDirectory = BuiltinAddonConfig.MCLastOpenedFolder;

            dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
            dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };
            dlg.ShowAddToFavorites      = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                BuiltinAddonConfig.MCLastOpenedFolder = Path.GetDirectoryName(dlg.FileName);
                OpenFileWithCheck(dlg.FileName, false);
            }
        }
Esempio n. 9
0
        private void SaveCatalogWithDialog()
        {
            OPMSaveFileDialog dlg = new OPMSaveFileDialog();

            dlg.Title            = Translator.Translate("TXT_SAVECATALOG");
            dlg.Filter           = Translator.Translate("TXT_CATALOG_FILTER");
            dlg.DefaultExt       = "ctx";
            dlg.InitialDirectory = BuiltinAddonConfig.MCLastOpenedFolder;

            dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
            dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };
            dlg.ShowAddToFavorites      = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                BuiltinAddonConfig.MCLastOpenedFolder = Path.GetDirectoryName(dlg.FileName);
                _bwSave.RunWorkerAsync(dlg.FileName);
                ShowWaitDialog("TXT_WAIT_SAVING_CATALOG");
            }
        }
        // ISampleGrabberCB Members

        public int BufferCB(double sampleTime, IntPtr pBuffer, int bufferLen)
        {
            if (ProTONEConfig.IsSignalAnalisysActive())
            {
                try
                {
                    if (sampleGrabberConfigured.WaitOne(0) && _actualAudioFormat != null)
                    {
                        const int fraction = 128;

                        byte[] allBytes = new byte[bufferLen];
                        Marshal.Copy(pBuffer, allBytes, 0, bufferLen);

                        int pos = 0;

                        double chunkTimeLen = (double)fraction / (double)_actualAudioFormat.nSamplesPerSec;
                        int    chunkSize    = fraction * _actualAudioFormat.nBlockAlign;
                        int    i            = 0;

                        do
                        {
                            int size = Math.Min(chunkSize, bufferLen - pos);

                            AudioSample smp = new AudioSample();
                            smp.RawSamples = new byte[size];
                            smp.SampleTime = sampleTime + i * chunkTimeLen;

                            Array.Copy(allBytes, pos, smp.RawSamples, 0, size);

                            samples.Enqueue(smp);

                            pos += size;
                            i++;
                        }while (pos < bufferLen);
                    }
                }
                catch { }
            }

            return(0);
        }
Esempio n. 11
0
        private void MergeCatalog()
        {
            if (_cat != null && _cat.IsValid)
            {
                OPMOpenFileDialog dlg = new OPMOpenFileDialog();
                dlg.Title            = Translator.Translate("TXT_MERGECATALOG");
                dlg.Filter           = Translator.Translate("TXT_CATALOG_FILTER");
                dlg.InitialDirectory = BuiltinAddonConfig.MCLastOpenedFolder;

                dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
                dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };
                dlg.ShowAddToFavorites      = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    BuiltinAddonConfig.MCLastOpenedFolder = Path.GetDirectoryName(dlg.FileName);
                    _bwMerge.RunWorkerAsync(dlg.FileName);
                    ShowWaitDialog("TXT_WAIT_MERGING_CATALOG");
                }
            }
        }
        private void btnAddFiles_Click(object sender, EventArgs e)
        {
            CursorHelper.ShowWaitCursor(this, true);

            OPMOpenFileDialog dlg = new OPMOpenFileDialog();

            dlg.Title            = Translator.Translate("TXT_SELECTTAGGEDFILES");
            dlg.Filter           = Translator.Translate("TXT_TAGGEDFILESFILTER");
            dlg.InitialDirectory = ProTONEConfig.LastOpenedFolder;
            dlg.Multiselect      = true;

            dlg.InheritAppIcon = false;
            dlg.Icon           = Resources.Tagging16.ToIcon();

            dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
            dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };
            dlg.ShowAddToFavorites      = true;


            if (dlg.ShowDialog() == DialogResult.OK && dlg.FileNames.Length > 0)
            {
                foreach (string file in dlg.FileNames)
                {
                    AddFile(file);
                }

                try
                {
                    string file = dlg.FileNames[0];
                    ProTONEConfig.LastOpenedFolder = Path.GetDirectoryName(file);
                }
                catch
                {
                    ProTONEConfig.LastOpenedFolder = dlg.InitialDirectory;
                }
            }

            CursorHelper.ShowWaitCursor(this, false);
            Wizard.CanMoveNext = lvFiles.Items.Count > 0;
        }
Esempio n. 13
0
        private void OnBrowseCatalog(object sender, EventArgs e)
        {
            OPMSaveFileDialog dlg = new OPMSaveFileDialog();

            dlg.Title            = Translator.Translate("TXT_SELECTCATALOG");
            dlg.Filter           = Translator.Translate("TXT_CATALOG_FILTER");
            dlg.DefaultExt       = "ctx";
            dlg.InitialDirectory = BuiltinAddonConfig.MCLastOpenedFolder;

            dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
            dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };
            dlg.ShowAddToFavorites      = true;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                BuiltinAddonConfig.MCLastOpenedFolder = Path.GetDirectoryName(dlg.FileName);

                (BkgTask as Task).CatalogPath = dlg.FileName;
                lblCatalogPath.Text           = Translator.Translate("TXT_CATALOGPATH", dlg.FileName);

                ThreadPool.QueueUserWorkItem(new WaitCallback(DisplayCatalogContents));
            }
        }
        public void OnUpdateMediaScreens()
        {
            bool showVU          = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.VUMeter);
            bool showWaveform    = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Waveform);
            bool showSpectrogram = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Spectrogram);

            pnlVuMeter.Visible = showVU;

            opmTableLayoutPanel1.RowStyles[0] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, showVU ? 70F : 0F);

            pnlWaveform.Visible = showWaveform;

            pnlSpectrogram.Visible = showSpectrogram;

            if (showSpectrogram && showWaveform)
            {
                opmTableLayoutPanel1.RowStyles[1] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F);
                opmTableLayoutPanel1.RowStyles[2] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F);
            }
            else if (showWaveform)
            {
                opmTableLayoutPanel1.RowStyles[1] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F);
                opmTableLayoutPanel1.RowStyles[2] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F);
            }
            else if (showSpectrogram)
            {
                opmTableLayoutPanel1.RowStyles[1] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F);
                opmTableLayoutPanel1.RowStyles[2] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F);
            }
            else
            {
                opmTableLayoutPanel1.RowStyles[1] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F);
                opmTableLayoutPanel1.RowStyles[2] = new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 0F);
            }

            UpdateLabels();
        }
        public MediaScreensOptionsPage()
        {
            InitializeComponent();

            chkShowPlaylist.Checked       = ProTONEConfig.MediaScreenActive(MediaScreen.Playlist);
            chkShowTrackInfo.Checked      = ProTONEConfig.MediaScreenActive(MediaScreen.TrackInfo);
            chkShowSignalAnalisys.Checked = ProTONEConfig.MediaScreenActive(MediaScreen.SignalAnalisys);
            chkShowBookmarkInfo.Checked   = ProTONEConfig.MediaScreenActive(MediaScreen.BookmarkInfo);

            chkVuMeter.Checked      = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.VUMeter);
            chkWaveform.Checked     = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Waveform);
            chkSpectrogram.Checked  = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Spectrogram);
            chkWCFInterface.Checked = ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.WCFInterface);

            this.chkShowPlaylist.CheckedChanged       += new System.EventHandler(this.OnSettingsChanged);
            this.chkShowTrackInfo.CheckedChanged      += new System.EventHandler(this.OnSettingsChanged);
            this.chkShowSignalAnalisys.CheckedChanged += new System.EventHandler(this.OnSettingsChanged);
            this.chkShowBookmarkInfo.CheckedChanged   += new System.EventHandler(this.OnSettingsChanged);

            this.chkVuMeter.CheckedChanged      += new System.EventHandler(this.OnSettingsChanged);
            this.chkWaveform.CheckedChanged     += new System.EventHandler(this.OnSettingsChanged);
            this.chkSpectrogram.CheckedChanged  += new System.EventHandler(this.OnSettingsChanged);
            this.chkWCFInterface.CheckedChanged += new System.EventHandler(this.OnSettingsChanged);
        }
 private void btnOK_Click(object sender, EventArgs e)
 {
     ProTONEConfig.SetFavoriteFolders(favoriteFoldersControl.FavoriteFolders,
                                      favoriteFoldersControl.FavoriteFoldersHiveName);
 }
Esempio n. 17
0
        private void HandleAction(ToolAction action)
        {
            try
            {
                if (!IsToolActionEnabled(action))
                {
                    return;
                }

                FileTaskForm activeFileTask = null;

                updateUiTimer.Stop();

                List <string> selItems = opmShellList.SelectedPaths;
                switch (action)
                {
                case ToolAction.ToolActionNewFolder:
                    opmShellList.CreateNewFolder();
                    return;

                case ToolAction.ToolActionBack:
                    opmShellList.ExploreBack();
                    return;

                case ToolAction.ToolActionFwd:
                    opmShellList.ExploreForward();
                    return;

                case ToolAction.ToolActionUp:
                    NavigateUp();
                    return;

                case ToolAction.ToolActionSearch:
                    SearchWizard.Tasks.Task taskSearch = new SearchWizard.Tasks.Task();
                    taskSearch.SearchPath = opmShellList.Path;
                    if (SearchWizardMain.Execute(taskSearch) == DialogResult.OK)
                    {
                        switch (taskSearch.Action)
                        {
                        case ToolAction.ToolActionProTONEEnqueue:
                        {
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                RemoteControlHelper.SendPlayerCommand(
                                    OPMedia.Runtime.ProTONE.RemoteControl.CommandType.EnqueueFiles,
                                    taskSearch.MatchingItems.ToArray());
                            }
                        }
                        break;

                        case ToolAction.ToolActionProTONEPlay:
                        {
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                RemoteControlHelper.SendPlayerCommand(
                                    OPMedia.Runtime.ProTONE.RemoteControl.CommandType.PlayFiles,
                                    taskSearch.MatchingItems.ToArray());
                            }
                        }
                        break;

                        case ToolAction.ToolActionJumpToItem:
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                opmShellList.JumpToItem(taskSearch.MatchingItems[0], false);
                            }
                            break;

                        case ToolAction.ToolActionTaggingWizard:
                        {
                            TaggedFileProp.TaggingWizard.Task taskTagging = new TaggedFileProp.TaggingWizard.Task();
                            foreach (string item in taskSearch.MatchingItems)
                            {
                                if (Directory.Exists(item))
                                {
                                    taskTagging.Files.AddRange(PathUtils.EnumFiles(item, "*.mp?", SearchOption.AllDirectories));
                                }
                                else if (File.Exists(item))
                                {
                                    taskTagging.Files.Add(item);
                                }
                            }

                            TaggingWizardMain.Execute(FindForm(), taskTagging);
                            ReloadProperties();
                        }
                        break;

                        case ToolAction.ToolActionCopy:
                            _pasteFileTask = new FEFileTaskForm(FileTaskType.Copy, taskSearch.MatchingItems, opmShellList.Path);
                            break;

                        case ToolAction.ToolActionCut:
                            _pasteFileTask = new FEFileTaskForm(FileTaskType.Move, taskSearch.MatchingItems, opmShellList.Path);
                            break;

                        case ToolAction.ToolActionDelete:
                            _deleteFileTask = new FEFileTaskForm(FileTaskType.Delete, taskSearch.MatchingItems, opmShellList.Path);
                            activeFileTask  = _deleteFileTask;
                            break;

                        case ToolAction.ToolActionLaunch:
                            if (taskSearch.MatchingItems.Count > 0)
                            {
                                opmShellList.OpenItem(taskSearch.MatchingItems[0]);
                            }
                            break;
                        }
                    }
                    return;

                case ToolAction.ToolActionReload:
                    GlobalReload();
                    return;

                case ToolAction.ToolActionTaggingWizard:
                {
                    TaggedFileProp.TaggingWizard.Task taskTagging = new TaggedFileProp.TaggingWizard.Task();
                    foreach (string item in opmShellList.SelectedPaths)
                    {
                        if (Directory.Exists(item))
                        {
                            taskTagging.Files.AddRange(PathUtils.EnumFiles(item, "*.mp?", SearchOption.AllDirectories));
                        }
                        else if (File.Exists(item))
                        {
                            taskTagging.Files.Add(item);
                        }
                    }

                    TaggingWizardMain.Execute(FindForm(), taskTagging);

                    if (taskTagging.TaskType != TaskType.MultiRename)
                    {
                        ReloadProperties();
                    }
                    else
                    {
                        RaiseNavigationAction(NavActionType.ActionSelectMultipleItems, opmShellList.SelectedPaths);
                    }
                }
                    return;

                case ToolAction.ToolActionCdRipper:
                {
                    OPMedia.Addons.Builtin.Navigation.FileExplorer.CdRipperWizard.Tasks.Task task =
                        new Navigation.FileExplorer.CdRipperWizard.Tasks.Task();

                    task.OutputFolder = opmShellList.Path;

                    CdRipperWizardMain.Execute(task);
                    ReloadNavigation();
                }
                break;

                case ToolAction.ToolActionCopy:
                    _pasteFileTask = new FEFileTaskForm(FileTaskType.Copy, opmShellList.SelectedPaths, opmShellList.Path);
                    return;

                case ToolAction.ToolActionCut:
                    _pasteFileTask = new FEFileTaskForm(FileTaskType.Move, opmShellList.SelectedPaths, opmShellList.Path);
                    return;

                case ToolAction.ToolActionPaste:
                    if (_pasteFileTask != null)
                    {
                        _pasteFileTask.DestFolder = opmShellList.Path;
                        activeFileTask            = _pasteFileTask;
                    }
                    break;

                case ToolAction.ToolActionDelete:
                    if (!opmShellList.IsInEditMode)
                    {
                        _deleteFileTask = new FEFileTaskForm(FileTaskType.Delete, opmShellList.SelectedPaths, opmShellList.Path);
                        activeFileTask  = _deleteFileTask;
                    }
                    break;

                case ToolAction.ToolActionRename:
                    Rename();
                    return;

                case ToolAction.ToolActionFavoritesAdd:
                {
                    List <string> favorites = new List <string>(ProTONEConfig.GetFavoriteFolders("FavoriteFolders"));
                    if (favorites.Contains(opmShellList.Path))
                    {
                        return;
                    }

                    favorites.Add(opmShellList.Path);
                    ProTONEConfig.SetFavoriteFolders(favorites, "FavoriteFolders");
                }
                    return;

                case ToolAction.ToolActionFavoritesManage:
                    new FavoriteFoldersManager("FavoriteFolders").ShowDialog();
                    return;

                case ToolAction.ToolActionProTONEEnqueue:
                {
                    List <String> items = opmShellList.SelectedPaths;
                    if (items.Count > 0)
                    {
                        RemoteControlHelper.SendPlayerCommand(
                            OPMedia.Runtime.ProTONE.RemoteControl.CommandType.EnqueueFiles,
                            items.ToArray());
                    }
                }
                break;

                case ToolAction.ToolActionProTONEPlay:
                {
                    List <String> items = opmShellList.SelectedPaths;
                    if (items.Count > 0)
                    {
                        RemoteControlHelper.SendPlayerCommand(
                            OPMedia.Runtime.ProTONE.RemoteControl.CommandType.PlayFiles,
                            items.ToArray());
                    }
                }
                break;
                }

                if (activeFileTask != null)
                {
                    RaiseNavigationAction(NavActionType.ActionCancelAutoPreview, null, null);

                    try
                    {
                        opmShellList.EnableAutoRefresh(false);
                        DialogResult dlg = activeFileTask.ShowDialog();
                    }
                    finally
                    {
                        if (activeFileTask.RequiresRefresh)
                        {
                            opmShellList.RefreshList(true);
                        }

                        opmShellList.EnableAutoRefresh(true);

                        if (activeFileTask.FileTaskType == FileTaskType.Delete)
                        {
                            _deleteFileTask = null;
                        }
                        else
                        {
                            _pasteFileTask = null;
                        }

                        activeFileTask = null;
                    }
                }
            }
            finally
            {
                updateUiTimer.Start();
            }
        }
        private void ExtractSamples(AudioSample smp)
        {
            if (smp == null || _actualAudioFormat == null || mediaPosition == null)
            {
                return;
            }

            double mediaTime = 0;

            mediaPosition.get_CurrentPosition(out mediaTime);

            double delay    = smp.SampleTime - mediaTime;
            double absDelay = Math.Abs(delay);

            // Discard samples too far in time from current media time
            if (absDelay > 1)
            {
                return;
            }

            //CalculateAverageDelay(delay * 1000);

            if (delay > 0)
            {
                Thread.Sleep(TimeSpan.FromSeconds(delay));
            }

            FilterState ms = GetFilterState();

            if (smp.RawSamples.Length <= 0 || ms != FilterState.Running || _actualAudioFormat == null)
            {
                return;
            }

            int bytesPerChannel      = _actualAudioFormat.wBitsPerSample / 8;
            int totalChannels        = _actualAudioFormat.nChannels;
            int totalChannelsInArray = Math.Min(2, totalChannels);

            int i = 0;

            while (i < smp.RawSamples.Length)
            {
                double[] channels = new double[totalChannelsInArray];
                Array.Clear(channels, 0, totalChannelsInArray);

                int j = 0;
                while (j < totalChannelsInArray)
                {
                    int k = 0;
                    while (k < bytesPerChannel)
                    {
                        if (bytesPerChannel <= 2)
                        {
                            channels[j] += (short)(smp.RawSamples[i] << (8 * k));
                        }
                        else
                        {
                            channels[j] += (int)(smp.RawSamples[i] << (8 * k));
                        }

                        i++;
                        k++;
                    }

                    j++;
                }

                if (channels.Length >= 2)
                {
                    _sampleData.Enqueue(new AudioSampleData((double)channels[0], (double)channels[1]));
                }
                else
                {
                    _sampleData.Enqueue(new AudioSampleData((double)channels[0], 0));
                }

                _gatheredSamples++;
                if (_gatheredSamples % _waveformWindowSize == 0)
                {
                    if (ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.VUMeter) ||
                        ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Waveform) ||
                        ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.WCFInterface))
                    {
                        AnalyzeWaveform(_sampleData.Skip(_sampleData.Count - _waveformWindowSize).Take(_waveformWindowSize).ToArray(),
                                        smp.SampleTime);
                    }
                }

                Thread.Yield();
            }

            AudioSampleData lostSample = null;

            while (_sampleData.Count > _fftWindowSize)
            {
                _sampleData.TryDequeue(out lostSample);
            }

            if (ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Spectrogram) ||
                ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.WCFInterface))
            {
                AnalyzeFFT(_sampleData.ToArray());
            }

            Thread.Yield();
        }
 public void Save()
 {
     ProTONEConfig.SetFavoriteFolders(this.FavoriteFolders,
                                      this.FavoriteFoldersHiveName);
 }
Esempio n. 20
0
        private void LoadFiles()
        {
            OPMOpenFileDialog dlg = new OPMOpenFileDialog();

            dlg.Title       = Translator.Translate("TXT_LOADMEDIAFILES");
            dlg.Multiselect = true;

            dlg.InheritAppIcon = false;
            dlg.Icon           = Resources.btnLoad.ToIcon((uint)Color.White.ToArgb());

            string filter = string.Empty;

            filter += MediaRenderer.DefaultInstance.AvailableFileTypesFilter;
            filter += Translator.Translate("TXT_ALL_FILES_FILTER");

            filter = filter.Replace("TXT_AUDIO_FILES", Translator.Translate("TXT_AUDIO_FILES"));
            filter = filter.Replace("TXT_VIDEO_FILES", Translator.Translate("TXT_VIDEO_FILES"));
            filter = filter.Replace("TXT_VIDEO_HD_FILES", Translator.Translate("TXT_VIDEO_HD_FILES"));
            filter = filter.Replace("TXT_PLAYLISTS", Translator.Translate("TXT_PLAYLISTS"));

            dlg.Filter = filter;

            dlg.FilterIndex      = ProTONEConfig.LastFilterIndex;
            dlg.InitialDirectory = ProTONEConfig.LastOpenedFolder;

            dlg.FillFavoriteFoldersEvt += () => { return(ProTONEConfig.GetFavoriteFolders("FavoriteFolders")); };
            dlg.AddToFavoriteFolders   += (s) => { return(ProTONEConfig.AddToFavoriteFolders(s)); };

            dlg.QueryDisplayName += (fsi) =>
            {
                if (fsi != null)
                {
                    if (fsi.ToUpperInvariant().EndsWith("CDA"))
                    {
                        CDAFileInfo cdfi = MediaFileInfo.FromPath(fsi) as CDAFileInfo;
                        if (cdfi != null)
                        {
                            return(cdfi.DisplayName);
                        }
                    }

                    return(Path.GetFileName(fsi));
                }

                return(string.Empty);
            };

            dlg.ShowAddToFavorites = true;

            dlg.OpenDropDownOptions = new List <OpenOption>(new OpenOption[]
            {
                new MediaPlayerOpenOption(CommandType.PlayFiles),
                new MediaPlayerOpenOption(CommandType.EnqueueFiles)
            });

            if (dlg.ShowDialog() == DialogResult.OK && dlg.FileNames.Length > 0)
            {
                CommandType openOption = CommandType.PlayFiles;
                try
                {
                    openOption = (CommandType)dlg.OpenOption;
                }
                catch
                {
                    openOption = CommandType.PlayFiles;
                }

                if (openOption == CommandType.EnqueueFiles)
                {
                    EnqueueFiles(dlg.FileNames);
                }
                else
                {
                    LoadFiles(dlg.FileNames);
                }

                ProTONEConfig.LastFilterIndex = dlg.FilterIndex;

                try
                {
                    string file = dlg.FileNames[0];
                    ProTONEConfig.LastOpenedFolder = Path.GetDirectoryName(file);
                }
                catch
                {
                    ProTONEConfig.LastOpenedFolder = dlg.InitialDirectory;
                }
            }
        }
        void _tmrUpdate_Tick(object sender, EventArgs e)
        {
            try
            {
                _tmrUpdate.Stop();

                if (ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.VUMeter))
                {
                    AudioSampleData vuData = MediaRenderer.DefaultInstance.VuMeterData;
                    if (vuData != null)
                    {
                        vuLeft.Value  = 0.5 * (vuLeft.Value + vuLeft.Maximum * vuData.LVOL);
                        vuRight.Value = 0.5 * (vuRight.Value + vuRight.Maximum * vuData.RVOL);
                    }
                    else
                    {
                        vuLeft.Value  = 0;
                        vuRight.Value = 0;
                    }
                }

                if (ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Waveform))
                {
                    gpWaveform.Reset(false);

                    double[][] waveformData = MediaRenderer.DefaultInstance.WaveformData;
                    if (waveformData != null && waveformData[0].Length > 0)
                    {
                        if (_prevWaveform == null)
                        {
                            _prevWaveform = new double[waveformData[0].Length];
                        }

                        for (int k = 0; k < _prevWaveform.Length; k++)
                        {
                            _prevWaveform[k] = 0.5 * (_prevWaveform[k] + waveformData[0][k]);
                        }

                        gpWaveform.MinVal = -1 * MediaRenderer.DefaultInstance.MaxLevel;
                        gpWaveform.MaxVal = MediaRenderer.DefaultInstance.MaxLevel;
                        gpWaveform.AddDataRange(_prevWaveform, ThemeManager.GradientGaugeColor1);
                    }
                    else
                    {
                        gpWaveform.Reset(true);
                    }
                }

                if (ProTONEConfig.SignalAnalisysFunctionActive(SignalAnalisysFunction.Spectrogram))
                {
                    double maxFftLevel = SpectrogramTransferFunction(MediaRenderer.DefaultInstance.MaxFFTLevel);

                    spSpectrogram.Reset(false);
                    spSpectrogram.MinVal = maxFftLevel / 2; // Min level = -6 dBM
                    spSpectrogram.MaxVal = maxFftLevel;     // Max level = 0 dBM

                    double[] spectrogramData = MediaRenderer.DefaultInstance.SpectrogramData;
                    if (spectrogramData != null && spectrogramData.Length > 0)
                    {
                        double[] spectrogramData2 = new double[spectrogramData.Length];
                        Array.Clear(spectrogramData2, 0, spectrogramData.Length);

                        double[] bands = new double[BandCount];
                        Array.Clear(bands, 0, BandCount);

                        int jBand = 0;

                        int div = spectrogramData.Length / (BandCount);

                        try
                        {
                            int maxSize = (int)Math.Min(BandCount, spectrogramData.Length);
                            for (int i = 0; i < maxSize; i++)
                            {
                                bands[i]  = Math.Max(0, Math.Min(maxFftLevel, SpectrogramTransferFunction(spectrogramData[i])));
                                _bands[i] = 0.5 * (_bands[i] + bands[i]);
                            }

                            spSpectrogram.AddDataRange(_bands, Color.Transparent);
                        }
                        catch (Exception ex)
                        {
                            string s = ex.Message;
                            spSpectrogram.Reset(true);
                            Array.Clear(_bands, 0, _bands.Length);
                        }
                    }
                    else
                    {
                        spSpectrogram.Reset(true);
                        Array.Clear(_bands, 0, _bands.Length);
                    }
                }
            }
            finally
            {
                _tmrUpdate.Start();
            }
        }