Exemplo n.º 1
0
        public override PacketData GetNextPacket()
        {
            CDDrive cdrom = (m_pParser as AudioCdFileParser).CDDrive;
            int     track = (m_pParser as AudioCdFileParser).Track;

            PacketData _data = new PacketData();

            _data.Buffer = new byte[m_lSampleSize * 2];
            uint size = (uint)_data.Buffer.Length;

            int bytesRead = cdrom.ReadTrack(track, _data.Buffer, ref size, (uint)(m_rtMediaPosition / UNITS),
                                            1,
                                            null);

            if (size > 0)
            {
                _data.Position    = 0;
                _data.Size        = (int)size;
                _data.SyncPoint   = true;
                _data.Start       = m_rtMediaPosition;
                _data.Stop        = _data.Start + UNITS;
                m_rtMediaPosition = _data.Stop;

                return(_data);
            }

            return(null);
        }
Exemplo n.º 2
0
        public static CDEntry BuildCdEntryByCddb(CDDrive cd, string diskId)
        {
            // Check the online FreeDB database.
            using (FreedbHelper fdb = new FreedbHelper(ProTONEConfig.CddbServerName, ProTONEConfig.CddbServerPort))
            {
                string             querySegment = cd.GetCDDBQuerySegment();
                QueryResult        qr;
                List <QueryResult> coll;
                string             s = fdb.Query(diskId + " " + querySegment, out qr, out coll);

                if (qr == null && coll != null && coll.Count > 0)
                {
                    qr = coll[0];
                }

                if (qr != null)
                {
                    CDEntry cdEntry = null;
                    s = fdb.Read(qr, out cdEntry);

                    return(cdEntry);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public override void Grab(CDDrive cd, Track track, string destFile, bool generateTags)
        {
            if (MustCancel())
            {
                return;
            }

            byte[] buff = base.GetTrackData(cd, track);

            if (MustCancel())
            {
                return;
            }

            ID3FileInfoSlim ifiSlim = new ID3FileInfoSlim();

            ifiSlim.Album  = track.Album;
            ifiSlim.Artist = track.Artist;
            ifiSlim.Genre  = track.Genre;
            ifiSlim.Title  = track.Title;
            ifiSlim.Track  = (short)track.Index;

            short year = 1900;

            if (short.TryParse(track.Year, out year))
            {
                ifiSlim.Year = year;
            }

            this.Options.WaveFormat = WaveFormatEx.Cdda;

            EncodeBuffer(buff, destFile, generateTags, ifiSlim);
        }
        /// <summary>
        /// Check CD is in the drive
        /// </summary>
        /// <returns></returns>
        private bool CheckCDDrive()
        {
            char[] driveLetters = CDDrive.GetCDDriveLetters();

            if (driveLetters.Length < 1)
            {
                _log.Error("No CD drives present");
                return(false);
            }

            Drive = new CDDrive();
            if (!Drive.Open(driveLetters[0]))
            {
                _log.Error("Unable to access drive with letter: " + driveLetters[0]);
                return(false);
            }

            if (!Drive.IsCDReady())
            {
                _log.Error("Drive with letter '" + driveLetters[0] + "' not ready.  Check the drive");
                return(false);
            }

            // try cycling the lock on the drive
            Drive.LockCD();
            Drive.Refresh();
            Drive.UnLockCD();

            // if we've got this far, we're okay to continue
            return(true);
        }
Exemplo n.º 5
0
 public AudioCD()
 {
     drive = new CDDrive();
     char[] Drives = CDDrive.GetCDDriveLetters();
     foreach (char drive in Drives)
     {
         DriveList.Add(drive.ToString());
     }
 }
Exemplo n.º 6
0
        public void RefreshDisk()
        {
            string rootPath = System.IO.Path.GetPathRoot(this.Path);

            if (!string.IsNullOrEmpty(rootPath))
            {
                char letter = rootPath.ToUpperInvariant()[0];
                {
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            switch (ProTONEConfig.AudioCdInfoSource)
                            {
                            case CddaInfoSource.CdText:
                                _cdEntry = BuildCdEntryByCdText(cd, _discId);
                                break;

                            case CddaInfoSource.Cddb:
                                _cdEntry = BuildCdEntryByCddb(cd, _discId);
                                break;

                            case CddaInfoSource.CdText_Cddb:
                            {
                                _cdEntry = BuildCdEntryByCdText(cd, _discId);
                                CDEntry cde = BuildCdEntryByCddb(cd, _discId);
                                _cdEntry = Merge(_cdEntry, cde);
                            }
                            break;

                            case CddaInfoSource.Cddb_CdText:
                            {
                                _cdEntry = BuildCdEntryByCddb(cd, _discId);
                                CDEntry cde = BuildCdEntryByCdText(cd, _discId);
                                _cdEntry = Merge(_cdEntry, cde);
                            }
                            break;

                            default:
                                break;
                            }

                            if (_cdEntry != null)
                            {
                                _cdEntry.PersistDisc();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        private StepDetail ProcessTrack(Track track)
        {
            string newFileName = string.Format("{0}.{1}",
                                               CdRipper.GetFileName(WordCasing.KeepCase, track, OutputFilePattern),
                                               this.EncoderSettings.FormatType.ToString().ToLowerInvariant());

            StepDetail detail = new StepDetail();

            detail.Description = Translator.Translate("TXT_PROCESSING_TRACK", track, newFileName);
            RaiseTaskStepInitEvent(detail);

            detail.Results   = Translator.Translate("TXT_UNHANDLED");
            detail.IsSuccess = false;

            try
            {
                _grabber = CdRipper.CreateGrabber(this.EncoderSettings.FormatType);
                char letter = DrivePath.ToUpperInvariant()[0];
                using (CDDrive cd = new CDDrive())
                {
                    if (cd.Open(letter) && cd.Refresh() && cd.HasAudioTracks())
                    {
                        string destFile = Path.Combine(OutputFolder, newFileName);

                        bool generateTagsFromMetadata = false;

                        switch (this.EncoderSettings.FormatType)
                        {
                        case AudioMediaFormatType.WAV:
                            break;

                        case AudioMediaFormatType.MP3:
                            Mp3EncoderSettings settings = (this.EncoderSettings as Mp3EncoderSettings);
                            (_grabber as GrabberToMP3).Options = settings.Options;
                            generateTagsFromMetadata           = settings.CopyInputFileMetadata;
                            break;
                        }

                        _grabber.Grab(cd, track, destFile, generateTagsFromMetadata);
                    }
                }

                detail.IsSuccess = true;
            }
            catch (Exception ex)
            {
                detail.Results = ex.Message;
            }

            return(detail);
        }
Exemplo n.º 8
0
        public static CDEntry BuildCdEntryByCdText(CDDrive cd, string diskId)
        {
            List <Track> tracks = null;

            if (cd.ReadCDText(out tracks))
            {
                CDEntry cdEntry = new CDEntry(diskId);
                cdEntry.Tracks.AddRange(tracks);

                return(cdEntry);
            }

            return(null);
        }
Exemplo n.º 9
0
        protected byte[] GetTrackData(CDDrive cd, Track track)
        {
            uint size = cd.TrackSize(track.Index);

            byte[] buff = new byte[size];
            int    x    = cd.ReadTrack(track.Index, buff, ref size, null);

            if (buff == null || buff.Length < 1)
            {
                throw new InvalidDataException("TXT_INVALID_TRACK_DATA");
            }

            return(buff);
        }
        private void PopulateAudioCDDrives()
        {
            cmbAudioCDDrives.Items.Clear();
            lvTracks.Items.Clear();

            DriveInfoItem selected = null;

            btnRefresh.Enabled = false;
            pbWaiting.Visible  = true;
            Application.DoEvents();

            ThreadPool.QueueUserWorkItem((c) =>
            {
                try
                {
                    DriveInfo[] audioCDs = CDDrive.GetAllAudioCDDrives();
                    foreach (DriveInfo di in audioCDs)
                    {
                        DriveInfoItem item = new DriveInfoItem(di);

                        MainThread.Post((d) => { cmbAudioCDDrives.Items.Add(item); });

                        if ((BkgTask as Task).DrivePath == null)
                        {
                            (BkgTask as Task).DrivePath = di.RootDirectory.FullName;
                        }

                        if (Path.Equals(di.RootDirectory.FullName, (BkgTask as Task).DrivePath))
                        {
                            selected = item;
                        }
                    }

                    MainThread.Post((d) =>
                    {
                        cmbAudioCDDrives.SelectedItem = selected;
                    });
                }
                finally
                {
                    MainThread.Post((d) =>
                    {
                        pbWaiting.Visible  = false;
                        btnRefresh.Enabled = true;
                    });
                }
            });
        }
Exemplo n.º 11
0
        private void ReadCDTextInformation(CDInfo cdInfo)
        {
            if (Settings.Current.DisableCDText)
            {
                return;
            }

            CDDrive cdDrive = new CDDrive();

            cdDrive.Open(CDEngine.DriveLetter);

            Ripper ripper = new Ripper(cdDrive);

            ripper.ReadCDText(CD);

            cdDrive.Close();
        }
Exemplo n.º 12
0
        public CDAFileInfo(string path, bool deepLoad)
            : base(path, false)
        {
            try
            {
                string rootPath = System.IO.Path.GetPathRoot(path);
                if (!string.IsNullOrEmpty(rootPath))
                {
                    char letter = rootPath.ToUpperInvariant()[0];
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            string trackStr = path.Replace(rootPath, "").ToLowerInvariant().Replace("track", "").Replace(".cda", "");
                            _track = -1;
                            if (int.TryParse(trackStr, out _track) && _track > 0)
                            {
                                if (cd.IsAudioTrack(_track))
                                {
                                    _duration = cd.GetSeconds(_track);

                                    _discId = cd.GetCDDBDiskID();

                                    // Check whether the disc is already added to our FreeDb lite database
                                    _cdEntry = CDEntry.LoadPersistentDisc(_discId);
                                    if (_cdEntry == null)
                                    {
                                        RefreshDisk();
                                    }

                                    return;
                                }
                            }
                        }
                    }

                    _cdEntry = null;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                _cdEntry = null;
            }
        }
Exemplo n.º 13
0
 public void ReproducirCD(char disp)
 {
     Disquetera = CDDrive.Open(disp);
     if (Disquetera == null)
     {
         Log.Instance.PrintMessage("Cannot read the CD Drive, the device is not ready.", MessageType.Error);
         throw new IOException();
     }
     FormatoSonido = FormatoSonido.CDA;
     PistaCD[] Pistas = LeerCD(disp);
     if (Pistas == null)
     {
         return;
     }
     PistasCD = Pistas;
     _output  = new WasapiOut(false, AudioClientShareMode.Shared, 100);
     _sound   = Disquetera.ReadTrack(Pistas[0]);
     _output.Initialize(_sound);
     _output.Play();
     Log.Instance.PrintMessage("CD has loaded correctly", MessageType.Correct);
 }
Exemplo n.º 14
0
        public void EncodeDisc(GUIFacadeControl facadeView, int getID)
        {
            GetID = getID;
            if (File.Exists(Config.GetFile(Config.Dir.Base, "lame_enc.dll")))
            {
                // Release the drives first for CDDRIVE to be able to open them
                BassMusicPlayer.ReleaseCDDrives();
                char[] Drives = CDDrive.GetCDDriveLetters();
                for (int i = 1; i < facadeView.Count; ++i)
                {
                    GUIListItem item = facadeView[i];
                    if ((!item.IsFolder) && (Array.IndexOf(Drives, item.Path[0]) > -1))
                    {
                        TrackInfo trackInfo = new TrackInfo();
                        if ((MusicTag)item.MusicTag == null)
                        {
                            MusicTag musicTag = new MusicTag();
                            musicTag.Artist = "Unknown Artist";
                            musicTag.Album  = "Unknown Album";
                            musicTag.Track  = Convert.ToInt16(item.Label.Substring(5));
                            musicTag.Title  = string.Format("Track {0:00}", musicTag.Track);
                            item.MusicTag   = musicTag;
                        }
                        trackInfo.MusicTag   = (MusicTag)item.MusicTag;
                        trackInfo.TrackCount = facadeView.Count - 1;
                        trackInfo.Item       = item;

                        try
                        {
                            EncodeTrack(trackInfo);
                        }
                        catch {}
                    }
                }
            }
        }
Exemplo n.º 15
0
        protected override void OnOpen()
        {
            try
            {
                this.drive = new CDDrive();
                this.drive.Open(this.DriveLetter);

                if (this.drive.IsCDReady() == false)
                {
                    throw new Exception("No CD in drive " + this.DriveLetter + ".");
                }

                if (this.drive.Refresh() == false)
                {
                    throw new Exception("Failed to read the drive table of contents of drive " + this.DriveLetter + ".");
                }

                if (this.drive.GetNumTracks() != 1)
                {
                    throw new Exception("3DO Games have only one track!");
                }
            }
            catch
            {
                // Cleanup
                try
                {
                    this.drive.Close();
                    this.drive = null;
                }
                catch { }

                // Rethrow
                throw;
            }
        }
Exemplo n.º 16
0
 public virtual void Grab(CDDrive cd, Track track, string destFile, bool generateTags)
 {
     throw new NotImplementedException(string.Format("{0} cannot be used to grab an audio CD.", this.GetType()));
 }
Exemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        public CDPlayerApp()
        {
            stringManager =
                new ResourceManager("SdlDotNetExamples.CDPlayer.Properties.Resources", Assembly.GetExecutingAssembly());
            InitializeComponent();
            this.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Title", CultureInfo.CurrentUICulture);
            this.label1.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "SelectDrive", CultureInfo.CurrentUICulture);
            this.buttonPlay.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Play", CultureInfo.CurrentUICulture);
            this.buttonPause.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Pause", CultureInfo.CurrentUICulture);
            this.buttonStop.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Stop", CultureInfo.CurrentUICulture);
            this.buttonEject.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Eject", CultureInfo.CurrentUICulture);
            this.labelStatus.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Track", CultureInfo.CurrentUICulture);
            this.buttonPrevious.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Previous", CultureInfo.CurrentUICulture);
            this.buttonNext.Text = SdlDotNetExamples.CDPlayer.CDPlayerApp.StringManager.GetString(
                "Next", CultureInfo.CurrentUICulture);
            this.KeyPreview = true;
            surf            =
                new Surface(
                    this.surfaceControl.Width,
                    this.surfaceControl.Height);
            if (File.Exists(Path.Combine(dataDirectory, "marble1.png")))
            {
                filePath = "";
            }
            SurfaceCollection marbleSurfaces = new SurfaceCollection();

            marbleSurfaces.Add(new Surface(Path.Combine(filePath, Path.Combine(dataDirectory, "marble1.png"))), new Size(50, 50));

            for (int i = 0; i < 1; i++)
            {
                //Create a new Sprite at a random location on the screen
                BounceSprite bounceSprite =
                    new BounceSprite(marbleSurfaces,
                                     new Point(rand.Next(0, 350),
                                               rand.Next(0, 200)));
                bounceSprite.Bounds = new Rectangle(new Point(0, 0), this.surfaceControl.Size);

                // Randomize rotation direction
                bounceSprite.AnimateForward = rand.Next(2) == 1 ? true : false;

                //Add the sprite to the SpriteCollection
                master.Add(bounceSprite);
            }

            //The collection will respond to mouse button clicks, mouse movement and the ticker.
            master.EnableMouseButtonEvent();
            master.EnableMouseMotionEvent();
            master.EnableVideoResizeEvent();
            master.EnableKeyboardEvent();
            master.EnableTickEvent();

            SdlDotNet.Core.Events.Fps   = 30;
            SdlDotNet.Core.Events.Tick += new EventHandler <TickEventArgs>(this.Tick);
            SdlDotNet.Core.Events.Quit += new EventHandler <QuitEventArgs>(this.Quit);

            try
            {
                int num = CDRom.NumberOfDrives;
                _drive = CDRom.OpenDrive(0);
                for (int i = 0; i < num; i++)
                {
                    comboBoxDrive.Items.Add(CDRom.DriveName(i));
                }

                if (comboBoxDrive.Items.Count > 0)
                {
                    comboBoxDrive.SelectedIndex = 0;
                }
            }
            catch (SdlException ex)
            {
                Console.WriteLine(ex);
            }
        }
        private void OnDriveSelected(object sender, EventArgs e)
        {
            Wizard.CanMoveNext = false;
            lvTracks.Items.Clear();

            DriveInfoItem item = cmbAudioCDDrives.SelectedItem as DriveInfoItem;

            if (item != null)
            {
                string rootPath = System.IO.Path.GetPathRoot(item.Path);
                if (!string.IsNullOrEmpty(rootPath))
                {
                    (BkgTask as Task).DrivePath = rootPath;

                    CDEntry cdEntry = null;
                    char    letter  = rootPath.ToUpperInvariant()[0];
                    using (CDDrive cd = new CDDrive())
                    {
                        if (cd.Open(letter) && cd.Refresh())
                        {
                            // Check whether the disc is already added to our persistent storage
                            string discId = cd.GetCDDBDiskID();
                            cdEntry = CDEntry.LoadPersistentDisc(discId);

                            if (cdEntry == null)
                            {
                                switch (ProTONEConfig.AudioCdInfoSource)
                                {
                                case CddaInfoSource.CdText:
                                    cdEntry = CDAFileInfo.BuildCdEntryByCdText(cd, cd.GetCDDBDiskID());
                                    break;

                                case CddaInfoSource.Cddb:
                                    cdEntry = CDAFileInfo.BuildCdEntryByCddb(cd, cd.GetCDDBDiskID());
                                    break;

                                case CddaInfoSource.CdText_Cddb:
                                {
                                    cdEntry = CDAFileInfo.BuildCdEntryByCdText(cd, cd.GetCDDBDiskID());
                                    CDEntry cde = CDAFileInfo.BuildCdEntryByCddb(cd, cd.GetCDDBDiskID());
                                    cdEntry = CDAFileInfo.Merge(cdEntry, cde);
                                }
                                break;

                                case CddaInfoSource.Cddb_CdText:
                                {
                                    cdEntry = CDAFileInfo.BuildCdEntryByCddb(cd, cd.GetCDDBDiskID());
                                    CDEntry cde = CDAFileInfo.BuildCdEntryByCdText(cd, cd.GetCDDBDiskID());
                                    cdEntry = CDAFileInfo.Merge(cdEntry, cde);
                                }
                                break;

                                default:
                                    break;
                                }

                                if (cdEntry != null)
                                {
                                    // Cache the disk to persistent storage for retrieving it faster later on
                                    cdEntry.PersistDisc();
                                }
                            }
                        }

                        if (cdEntry != null)
                        {
                            for (int i = 1; i <= cdEntry.NumberOfTracks; i++)
                            {
                                double size     = cd.TrackSize(i);
                                int    duration = cd.GetSeconds(i);

                                ListViewItem lvItem = new ListViewItem(i.ToString());

                                lvItem.SubItems.Add(TimeSpan.FromSeconds(duration).ToString());
                                lvItem.SubItems.Add(((size / (1024 * 1024)).ToString("F")) + " MB");

                                OPMListViewSubItem subItem = new OPMListViewSubItem(tbEditAlbum, lvItem,
                                                                                    cdEntry.Tracks[i - 1].Album ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);

                                subItem = new OPMListViewSubItem(tbEditArtist, lvItem,
                                                                 cdEntry.Tracks[i - 1].Artist ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);

                                subItem = new OPMListViewSubItem(tbEditTitle, lvItem,
                                                                 cdEntry.Tracks[i - 1].Title ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);

                                subItem = new OPMListViewSubItem(cmbEditgenre, lvItem,
                                                                 cdEntry.Tracks[i - 1].Genre ?? string.Empty);
                                subItem.ReadOnly = false;
                                lvItem.SubItems.Add(subItem);

                                if (Wizard.RepeatCount == 0)
                                {
                                    lvItem.ImageIndex = 1;
                                }
                                else
                                {
                                    //lvItem.ImageIndex = ((BkgTask as Task).Tracks.Contains(i)) ? 1 : 0;
                                }

                                lvItem.Tag = cdEntry.Tracks[i - 1];

                                lvTracks.Items.Add(lvItem);
                            }
                        }
                    }
                }
            }

            CheckNextButton();
        }
Exemplo n.º 19
0
        private static void SaveTrack(TrackInfo trackInfo)
        {
            string targetFileName = trackInfo.MusicTag.Title;

            if (m_Drive.Open(trackInfo.Item.Path[0]))
            {
                char[] Drives = CDDrive.GetCDDriveLetters();
                if ((Array.IndexOf(Drives, trackInfo.Item.Path[0]) > -1) && (m_Drive.IsCDReady()) && (m_Drive.Refresh()))
                {
                    try
                    {
                        m_Drive.LockCD();
                        if (dlgProgress.IsCanceled)
                        {
                            m_CancelRipping = true;
                        }
                        if (!m_CancelRipping)
                        {
                            try
                            {
                                try
                                {
                                    WaveFormat Format    = new WaveFormat(44100, 16, 2);
                                    BE_CONFIG  mp3Config = new BE_CONFIG(Format);
                                    if (mp3VBR)
                                    {
                                        mp3Config.format.lhv1.bEnableVBR = 1;
                                        if (mp3FastMode)
                                        {
                                            mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NEW;
                                        }
                                        else
                                        {
                                            mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_DEFAULT;
                                        }
                                        mp3Config.format.lhv1.nVBRQuality = mp3Quality;
                                    }
                                    else if (mp3CBR)
                                    {
                                        mp3Config.format.lhv1.bEnableVBR = 0;
                                        mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE;
                                        mp3Config.format.lhv1.dwBitrate  = Convert.ToUInt16(Rates[mp3BitRate]);
                                    }
                                    else
                                    {
                                        mp3Config.format.lhv1.bEnableVBR = 1;
                                        mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_ABR;
                                        uint ConToKbwVbrAbr_bps = Convert.ToUInt16(Rates[mp3BitRate]);
                                        mp3Config.format.lhv1.dwVbrAbr_bps = ConToKbwVbrAbr_bps * 1000;
                                    }

                                    if (mp3MONO)
                                    {
                                        mp3Config.format.lhv1.nMode = MpegMode.MONO;
                                    }

                                    mp3Config.format.lhv1.bWriteVBRHeader = 1;

                                    Stream WaveFile = new FileStream(trackInfo.TempFileName, FileMode.Create, FileAccess.Write);
                                    m_Writer = new Mp3Writer(WaveFile, Format, mp3Config);
                                    if (!m_CancelRipping)
                                    {
                                        try
                                        {
                                            Log.Info("CDIMP: Processing track {0}", trackInfo.MusicTag.Track);

                                            DateTime InitTime = DateTime.Now;
                                            if (
                                                m_Drive.ReadTrack(trackInfo.MusicTag.Track, new CdDataReadEventHandler(WriteWaveData),
                                                                  new CdReadProgressEventHandler(CdReadProgress)) > 0)
                                            {
                                                if (dlgProgress.IsCanceled)
                                                {
                                                    m_CancelRipping = true;
                                                }
                                                if (!m_CancelRipping)
                                                {
                                                    TimeSpan Duration = DateTime.Now - InitTime;
                                                    double   Speed    = m_Drive.TrackSize(trackInfo.MusicTag.Track) / Duration.TotalSeconds /
                                                                        Format.nAvgBytesPerSec;
                                                    Log.Info("CDIMP: Done reading track {0} at {1:0.00}x speed", trackInfo.MusicTag.Track, Speed);
                                                }
                                            }
                                            else
                                            {
                                                Log.Info("CDIMP: Error reading track {0}", trackInfo.MusicTag.Track);
                                                m_Writer.Close();
                                                WaveFile.Close();
                                                if (File.Exists(trackInfo.TempFileName))
                                                {
                                                    try
                                                    {
                                                        File.Delete(trackInfo.TempFileName);
                                                    }
                                                    catch {}
                                                }
                                                //progressBar1.Value = 0;
                                            }
                                        }
                                        finally
                                        {
                                            m_Writer.Close();
                                            m_Writer = null;
                                            WaveFile.Close();
                                            Lame_encDll.beWriteVBRHeader(trackInfo.TempFileName);
                                        }
                                    }
                                }
                                finally {}
                            }
                            finally
                            {
                                m_Drive.Close();
                            }
                        }
                    }
                    finally
                    {
                        //progressBar1.Value = 0;
                    }
                }
                if (dlgProgress.IsCanceled)
                {
                    m_CancelRipping = true;
                }
                if (m_CancelRipping)
                {
                    if (File.Exists(trackInfo.TempFileName))
                    {
                        File.Delete(trackInfo.TempFileName);
                    }
                    m_Drive.Close();
                }
            }
        }
Exemplo n.º 20
0
        private static void ThreadEncodeTrack()
        {
            m_Ripping = true;

            try
            {
                CreateTempFolder();
                if (mp3Background)
                {
                    GUIWaitCursor.Show();
                }
                else if (dlgProgress != null)
                {
                    dlgProgress.Reset();
                    dlgProgress.SetPercentage(0);
                    dlgProgress.StartModal(GetID);
                    dlgProgress.Progress();
                    dlgProgress.ShowProgressBar(true);
                }

                while (importQueue.Count > 0)
                {
                    TrackInfo trackInfo = (TrackInfo)importQueue.Dequeue();
                    if ((dlgProgress != null) && !mp3Background)
                    {
                        if (importQueue.Count > 0)
                        {
                            dlgProgress.SetHeading(
                                string.Format(GUILocalizeStrings.Get(1105) + " ({0} " + GUILocalizeStrings.Get(1104) + ")",
                                              importQueue.Count + 1));
                        }
                        else
                        {
                            dlgProgress.SetHeading(GUILocalizeStrings.Get(1103));
                        }

                        dlgProgress.SetLine(2,
                                            string.Format("{0:00}. {1} - {2}", trackInfo.MusicTag.Track, trackInfo.MusicTag.Artist,
                                                          trackInfo.MusicTag.Title));
                        //dlgProgress.SetLine(2, trackInfo.TempFileName);
                        if (dlgProgress.IsCanceled)
                        {
                            m_CancelRipping = true;
                        }
                    }

                    if (!m_CancelRipping)
                    {
                        m_Drive = new CDDrive();
                        SaveTrack(trackInfo);
                        if (File.Exists(trackInfo.TempFileName) && !m_CancelRipping)
                        {
                            #region Tagging

                            try
                            {
                                Tags tags = Tags.FromFile(trackInfo.TempFileName);
                                tags["TRCK"] = trackInfo.MusicTag.Track.ToString() + "/" + trackInfo.TrackCount.ToString();
                                tags["TALB"] = trackInfo.MusicTag.Album;
                                tags["TPE1"] = trackInfo.MusicTag.Artist;
                                tags["TIT2"] = trackInfo.MusicTag.Title;
                                tags["TCON"] = trackInfo.MusicTag.Genre;
                                if (trackInfo.MusicTag.Year > 0)
                                {
                                    tags["TYER"] = trackInfo.MusicTag.Year.ToString();
                                }
                                tags["TENC"] = "MediaPortal / Lame";
                                tags.Save(trackInfo.TempFileName);
                            }
                            catch
                            {
                            }

                            #endregion

                            #region Database

                            try
                            {
                                if (!Directory.Exists(trackInfo.TargetDir))
                                {
                                    Directory.CreateDirectory(trackInfo.TargetDir);
                                }

                                if (File.Exists(trackInfo.TargetFileName))
                                {
                                    if (mp3ReplaceExisting)
                                    {
                                        File.Delete(trackInfo.TargetFileName);
                                    }
                                }

                                if (!File.Exists(trackInfo.TargetFileName))
                                {
                                    File.Move(trackInfo.TempFileName, trackInfo.TargetFileName);
                                }

                                if (File.Exists(trackInfo.TargetFileName) && mp3Database)
                                {
                                    if (importUnknown || (trackInfo.MusicTag.Artist != "Unknown Artist") ||
                                        (trackInfo.MusicTag.Album != "Unknown Album"))
                                    {
                                        MusicDatabase dbs = MusicDatabase.Instance;
                                        dbs.AddSong(trackInfo.TargetFileName);
                                    }
                                }
                            }
                            catch
                            {
                                Log.Info("CDIMP: Error moving encoded file {0} to new location {1}", trackInfo.TempFileName,
                                         trackInfo.TargetFileName);
                            }

                            #endregion
                        }
                    }
                }
                if (mp3Background)
                {
                    GUIWaitCursor.Hide();
                }
                else
                {
                    dlgProgress.Close();
                }
            }
            finally
            {
                CleanupTempFolder();
            }
            m_CancelRipping = false;
            m_Ripping       = false;
        }
        public CompactDiscMusicExtractor()
        {
            m_drive = new CDDrive();

            m_drive.CDRemoved += OnCompactDiscRemoved;
        }
Exemplo n.º 22
0
 public override void Grab(CDDrive cd, Track track, string destFile, bool generateTags)
 {
     byte[] buff = base.GetTrackData(cd, track);
     WriteBuffer(buff, WaveFormatEx.Cdda, destFile);
 }
Exemplo n.º 23
0
 protected override void OnClose()
 {
     this.drive.Close();
     this.drive = null;
 }