예제 #1
0
        public static TagModel CreateClone(TagModel other)
        {
            TagModel tagModel = DocNode.Create <TagModel>();

            tagModel.Init(other.FileNameFull, other.ToTag(), other.Bitrate.Value);
            return(tagModel);
        }
예제 #2
0
파일: Document.cs 프로젝트: MRoc/puremp3
        public void RequestPlaying(string filename)
        {
            TagModel model = DocNode.Create <TagModel>();

            model.FileNameFull = filename;

            try
            {
                int tagSize = TagUtils.TagSizeV2(new FileInfo(filename));
                using (Stream stream = VirtualDrive.OpenInStream(filename))
                {
                    stream.Seek(tagSize, SeekOrigin.Begin);
                    model.Bitrate.Value = ID3MediaFileHeader.MP3Header.ReadBitrate(
                        stream, VirtualDrive.FileLength(filename));
                }
            }
            catch (Exception)
            {
            }

            FileInfo fileInfo = new FileInfo(filename);

            FileTreeModel.ExpandAndSelect(fileInfo.DirectoryName, true);

            RequestPlaying(model);
        }
예제 #3
0
        public static void TestTagModelIsPlayingUpdater_IsPlaying()
        {
            PlayerModel model = new PlayerModel();

            TagModelList tml = DocNode.Create <TagModelList>();

            tml.SetFiles(TestTagModel.testFileNames);

            PlayerModelIsPlayingUpdater updater = new PlayerModelIsPlayingUpdater();

            updater.Model = model;
            updater.Items = tml.Items;

            for (int i = 0; i < tml.Items.Count; ++i)
            {
                model.CurrentModel.Value = tml[i];

                for (int j = 0; j < tml.Items.Count; ++j)
                {
                    UnitTest.Test(tml[j].IsPlaying.Value == (i == j));
                }
            }

            model.CurrentModel.Value = null;
        }
예제 #4
0
        private void OnFileRequest(object sender, AccessObserver.AccessObserverEventArgs args)
        {
            Action action = null;

            switch (args.Request)
            {
            case AccessObserver.AccessRequest.LockExclusive:
                action = delegate
                {
                    if (Model.CurrentModel.Value.FileNameFull == args.ObservedId)
                    {
                        PausePosition = (long)Player.Position.TotalMilliseconds;

                        Controller.Stop();

                        System.Threading.Thread.Sleep(100);

                        VirtualDrive.ObserverFreeShared.Register(Model.CurrentModel.Value.FileNameFull, OnFileRequest);
                    }
                };
                break;

            case AccessObserver.AccessRequest.FreeShared:
                action = delegate
                {
                    VirtualDrive.ObserverFreeShared.Unregister(args.ObservedId);

                    if (Model.CurrentModel.Value.FileNameFull == args.ObservedId)
                    {
                        if (String.IsNullOrEmpty(args.NewObservedId))
                        {
                            Model.CurrentModel.Value = null;
                        }
                        else
                        {
                            try
                            {
                                TagModel model = DocNode.Create <TagModel>();
                                model.Load(args.NewObservedId);
                                Model.CurrentModel.Value = model;

                                Controller.Play();
                                Player.Position = new TimeSpan(0, 0, 0, 0, (int)PausePosition);
                            }
                            catch (Exception e)
                            {
                                Logger.WriteLine(Tokens.Exception, e);
                            }
                        }
                    }
                };
                break;
            }

            if (!Object.ReferenceEquals(action, null))
            {
                Player.Dispatcher.Invoke(action);
            }
        }
예제 #5
0
파일: Playlist.cs 프로젝트: MRoc/puremp3
        public static void TestBasic()
        {
            Playlist playlist = DocNode.Create <Playlist>();

            playlist.Player = new PlayerModel();

            UnitTest.Test(Object.ReferenceEquals(playlist.IsPlayingUpdater.Model, playlist.Player));
            UnitTest.Test(Object.ReferenceEquals(playlist.IsPlayingUpdater.Items, playlist.Items));
        }
예제 #6
0
        public static MultiTagModelItem Create(ID3.FrameDescription.FrameType type)
        {
            switch (type)
            {
            case ID3.FrameDescription.FrameType.Picture:
                return(DocNode.Create <MultiTagModelItemPicture>());

            default:
                return(DocNode.Create <MultiTagModelItem>());
            }
        }
예제 #7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            WorkerThreadPool.Instance.InvokingThread = new WpfDispatcher(Dispatcher);
            History.Instance.AllowedThreadId         = Thread.CurrentThread.ManagedThreadId;

            ApplySkin(new Uri("/CoreControls;component/resources/BaseSkin.xaml", UriKind.Relative));

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                       "PureMp3.Resources.Texts.xml"))
            {
                LocalizationDatabase.Instance.Load(stream);
            }

            try
            {
                AppPreferences.Load(App.AppName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(ex.StackTrace);
            }

            try
            {
                RecycleBin.Instance.RootDir = App.AppRecycleFolder;
                RecycleBin.Instance.DeleteContent();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(ex.StackTrace);
            }

            Doc = DocNode.Create <Document>();
            History.Instance.Root = Doc;

            try
            {
                keyboardListener.KeyDown += new RawKeyEventHandler(keyboardListener_KeyDown);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(ex.StackTrace);
            }
        }
예제 #8
0
        public void Add(string fileName, Tag tag, int bitrate)
        {
            if (Contains(fileName))
            {
                throw new Exception("Can't add twice!");
            }

            TagModel model = DocNode.Create <TagModel>();

            model.Init(fileName, tag, bitrate);

            model.IsSelected.TransactionIdModeToUse = DocObj <bool> .TransactionIdMode.UseFixed;
            model.IsSelected.FixedTransactionId     = GetHashCode();
            Items.Add(model);
        }
예제 #9
0
파일: Preferences.cs 프로젝트: MRoc/puremp3
        public Preferences()
        {
            PrefsCommon           = DocNode.Create <PreferencesCommon>();
            PrefsAlbumRecognition = DocNode.Create <PreferencesAlbumRecognition>();
            PrefsFilenameToTag    = DocNode.Create <PreferencesFilenameToTag>();
            PrefsAlbumToLibrary   = DocNode.Create <PreferencesAlbumToToLibrary>();
            PrefsPreparse         = DocNode.Create <PreferencesPreparse>();
            PrefsFreedb           = DocNode.Create <PreferencesWebToTag>();

            (PrefsCommon.Version.Item as TagVersionEnum).PropertyChanged
                += new PropertyChangedEventHandler(OnVersionChanged);

            ResolveChildrenLinks();

            PrefsPreparse.SetVersion(PrefsCommon.Version.Item as TagVersionEnum);
        }
예제 #10
0
파일: Document.cs 프로젝트: MRoc/puremp3
        public Document()
        {
            Preferences = Preferences.LoadPreferences();

            FileTreeModel = new FileTreeModel();
            FileTreeModel.PropertyChanged += OnTreeNodeSelectionChanged;
            FileTreeModel.Help             = new LocalizedText("FileTreeModelHelp");

            Editor = DocNode.Create <TagModelEditor>();
            Editor.Path.PropertyChanged += OnPathChanged;

            IsBatchActive = new DocObj <bool>();
            VisibleTab    = new DocObj <int>();

            PlayerModel     = DocNode.Create <PlayerModel>();
            Playlist        = DocNode.Create <Playlist>();
            Playlist.Player = PlayerModel;

            PlaylistRouter             = new PlaylistRouter();
            PlaylistRouter.Playlist    = Playlist.Items;
            PlaylistRouter.EditorList  = Editor.TagModelList.Items;
            PlaylistRouter.PlayerModel = PlayerModel;
            PlaylistRouter.VisibleTab  = VisibleTab;

            PlayerController = DocNode.Create <PlayerController>();
            PlayerCommands   = new PlayerCommands(PlayerController, PlaylistRouter, PlaylistRouter);

            IsPlayingUpdater       = new PlayerModelIsPlayingUpdater();
            IsPlayingUpdater.Model = PlayerModel;
            IsPlayingUpdater.Items = Editor.TagModelList.Items;

            FileTreeModel.CommandsProvider += CommandsForNode;

            try
            {
                InitLibrary();
            }
            catch (Exception ex)
            {
                CoreUtils.CrashDumpWriter.DumpException(ex, "PureMp3", "*****@*****.**");
            }

            IsWorkerThreadActive      = new DocObj <bool>();
            IsWorkerThreadActive.Help = new LocalizedText("IsWorkerThreadActive");

            //XmlUtils.DumpXml(this.ToXmlDump());
        }
예제 #11
0
        public TagModelEditor()
        {
            MultiTagEditor = DocNode.Create <MultiTagModel>();
            MultiTagEditor.IsFixed.Value = true;

            TagModelList = DocNode.Create <TagModelList>();
            Dirty        = new DocObj <bool>();
            RefreshFlank = new DocObj <bool>();
            Path         = new DocObj <string>();

            RefreshFlank.Hook += OnFileListRefreshHook;
            Path.Hook         += OnPathHook;

            MultiTagEditor.TagModelList = TagModelList;

            History.Instance.MarkDirty = MarkDirty;
        }
예제 #12
0
        public static TagModelItem Create(ID3.FrameDescription.FrameType type)
        {
            switch (type)
            {
            case ID3.FrameDescription.FrameType.Picture:
                return(DocNode.Create <TagModelItemPicture>());

            case ID3.FrameDescription.FrameType.Text:
                return(DocNode.Create <TagModelItemText>());

            case ID3.FrameDescription.FrameType.Comment:
                return(DocNode.Create <TagModelItemComment>());

            default:
                return(DocNode.Create <TagModelItem>());
            }
        }