コード例 #1
0
        private void GenerateSingleLine(TrackWriter trk, SimulationPoint PointCur, SimulationPoint PointNext, Vector2d PointTarget, double OffsetMult = 1.0) //Generates the line corresponding to a single contact-point, given its position on iteration 1, the next frame's momentum tick, and the intended final momentum tick
        {
            const double vert_displacement = 1.0e-3;                                                                                                         //How far to displace the contact-point along the line
            const double width             = 1.0e-5;                                                                                                         //How wide the line is

            bool   inverse         = false;
            var    TargetDirection = PointTarget - PointNext.Location; //Normalised direction to move the point
            double speedRequired   = TargetDirection.Length;           //The speed required to get the momentum tick point to the correct location

            TargetDirection /= TargetDirection.Length;                 //Normalised
            var NormalDirection = TargetDirection.PerpendicularLeft;   //Line normal (initially assumes not inverted)

            if (Vector2d.Dot(PointCur.Momentum, NormalDirection) <= 0) //If the line's direction is wrong, it needs to be inverted
            {
                inverse         = true;
                NormalDirection = TargetDirection.PerpendicularRight;
            }

            double multiplierRequired = speedRequired / RedLine.ConstAcc; //These will be converted to ints later
            int    multilinesRequired = (int)Math.Ceiling(multiplierRequired / 255.0);

            multiplierRequired /= (double)multilinesRequired; //This now represents the multiplier per line

            var lineCentre = PointCur.Location - vert_displacement * OffsetMult * NormalDirection;
            var lineLeft   = lineCentre - 0.5 * width * TargetDirection;
            var lineRight  = lineCentre + 0.5 * width * TargetDirection;

            for (int i = 0; i < multilinesRequired; i++)
            {
                lines.Add(CreateLine(trk, lineLeft, lineRight, LineType.Red, inverse, (int)multiplierRequired));
                lineLeft  += (vert_displacement / 100.0) * NormalDirection;
                lineRight += (vert_displacement / 100.0) * NormalDirection;
            }
        }
コード例 #2
0
        public override void Generate_Internal(TrackWriter trk)
        {
            //int startFrame = 0;
            Random rnd = new Random();

            rnd.NextDouble();

            int   curFrame          = game.Track.Offset;
            Rider curRider          = game.Track.Timeline.GetFrame(curFrame);
            Rider curRiderIter1     = game.Track.Timeline.GetFrame(curFrame, 1);
            Rider nextMomentumRider = curRider.Simulate(game.Track.getTrack(), 0);

            Vector2d[] defaultRider = RiderConstants.createDefaultRider();
            var        rotationMat  = Matrix2d.CreateRotation(MathHelper.DegreesToRadians(rotation));



            for (int i = 0; i < defaultRider.Length; i++)
            {
                var riderRotated = new Vector2d(rotationMat.M11 * defaultRider[i].X + rotationMat.M21 * defaultRider[i].Y,
                                                rotationMat.M12 * defaultRider[i].X + rotationMat.M22 * defaultRider[i].Y);
                var    target = curRider.Body[0].Location + riderRotated + speed;
                double offset = 1.0 + rnd.NextDouble();
                GenerateSingleLine(trk, curRiderIter1.Body[i], nextMomentumRider.Body[i], target, offset);
            }
            return;
        }
コード例 #3
0
        protected GameLine SelectLine(TrackWriter trk, Vector2d position, out bool knob)
        {
            knob = false;
            var zoom = game.Track.Zoom;
            var ends = LineEndsInRadius(trk, position, SnapRadius);

            if (ends.Length > 0)
            {
                knob = true;
                return(ends[0]);
            }
            var lines =
                trk.GetLinesInRect(
                    new DoubleRect((Vector2d)position - new Vector2d(24, 24),
                                   new Vector2d(24 * 2, 24 * 2)),
                    false);

            foreach (var line in lines)
            {
                double lnradius = line.Width;
                var    angle    = Angle.FromLine(line.Position, line.Position2);
                var    rect     = Utility.GetThickLine(
                    line.Position,
                    line.Position2,
                    angle,
                    lnradius * 2);
                if (Utility.PointInRectangle(rect,
                                             position))
                {
                    return(line);
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: Sequence.cs プロジェクト: xiaotan2/piano
    /// <summary>
    /// Saves the Sequence as a MIDI file.
    /// </summary>
    /// <param name="fileName">
    /// The name to use for saving the MIDI file.
    /// </param>
    public void Save(string fileName)
    {
        #region Require

        if (disposed)
        {
            throw new ObjectDisposedException("Sequence");
        }
        else if (fileName == null)
        {
            throw new ArgumentNullException("fileName");
        }

        #endregion

        FileStream stream = new FileStream(fileName, FileMode.Create,
                                           FileAccess.Write, FileShare.None);

        using (stream)
        {
            properties.Write(stream);

            TrackWriter writer = new TrackWriter();

            foreach (Track trk in tracks)
            {
                writer.Track = trk;
                writer.Write(stream);
            }
        }
    }
コード例 #5
0
        public void CreateNewDatabase()
        {
            Crawler.Stop();
            TrackWriter.Stop();

            if (rg != null)
            {
                rg.Cancel();
            }

            iTunes.Cancel = true;

            System.Threading.Thread.Sleep(200);

            normal.AllowEvents = false;
            normal.ReleaseAllFilters();
            normal.AllowEvents = true;

            artwork.CurrentTrack          = null;
            artwork.TemporaryTrack        = null;
            normal.Artwork.CurrentTrack   = null;
            normal.Artwork.TemporaryTrack = null;

            Database.CreateNewDatabase(false);

            TargetPlaylistName = Localization.MY_PLAYLIST;

            normal.RefreshAll(true);
        }
コード例 #6
0
        private void autoNumber()
        {
            List <Track> tl = tracklist.SelectedTracks;

#if DEBUG
            List <Track> q = tracklist.Queue.ToList();
            q.RemoveAll(t => tl.IndexOf(t) < 0);
            for (int i = 0; i < tl.Count; i++)
            {
                System.Diagnostics.Debug.Assert(tl[i] == q[i]);
            }
#endif

            int low = 1;
            IEnumerable <Track> sum = tl.FindAll(t => t.TrackNum > 0);
            if (sum.Any())
            {
                low = Math.Max(1, sum.Min(t => t.TrackNum));
            }

            frmNumberTracks nt = new frmNumberTracks(low, tl.Count);
            nt.ShowDialog(this);
            if (nt.DialogResult == DialogResult.OK)
            {
                int num = nt.First;
                for (int i = 0; i < tl.Count; i++)
                {
                    tl[i].TrackNum    = num++;
                    tl[i].ChangeType |= ChangeType.WriteTags;
                }
                tracklist.Invalidate();
                TrackWriter.AddToUnsavedTracks(tl);
            }
        }
コード例 #7
0
        public override void Generate_Internal(TrackWriter trk)
        {
            var points = new List <Vector2d>();

            for (double frac = 0.0; frac < 1.0; frac += 1.0 / (double)lineCount)
            {
                double ang = frac * 2.0 * Math.PI;
                points.Add(position + radius * new Vector2d(Math.Cos(ang), Math.Sin(ang)));
            }
            if (invert != reverse) // XOR
            {
                for (int i = 1; i < points.Count; i++)
                {
                    addLine(trk, points[i], points[i - 1], lineType, reverse);
                }
                addLine(trk, points[0], points[points.Count - 1], lineType, reverse);
            }
            else
            {
                for (int i = 1; i < points.Count; i++)
                {
                    addLine(trk, points[i - 1], points[i], lineType, reverse);
                }
                addLine(trk, points[points.Count - 1], points[0], lineType, reverse);
            }
        }
コード例 #8
0
        public void DeleteSubscriptionFiles(Callback Callback)
        {
            List <string> files  = new List <string>();
            List <Track>  tracks = new List <Track>();

            List <PodcastEpisode> ppe = this.Episodes.ToList();

            foreach (PodcastEpisode pe in ppe)
            {
                if (pe.Track != null)
                {
                    tracks.Add(pe.Track);
                    if (pe.Track.ConfirmExists)
                    {
                        files.Add(pe.Track.FilePath);
                    }
                }
            }

            Database.RemoveFromLibrary(tracks);

            if (files.Count > 0)
            {
                foreach (string s in files)
                {
                    TrackWriter.AddToDeleteList(s);
                }
            }
            TrackWriter.DeleteItems();
            this.Close(Callback);
        }
コード例 #9
0
ファイル: Sequence.cs プロジェクト: xiaotan2/piano
    private void SaveDoWork(object sender, DoWorkEventArgs e)
    {
        string fileName = (string)e.Argument;

        FileStream stream = new FileStream(fileName, FileMode.Create,
                                           FileAccess.Write, FileShare.None);

        using (stream)
        {
            properties.Write(stream);

            TrackWriter writer = new TrackWriter();

            float percentage;

            for (int i = 0; i < tracks.Count && !saveWorker.CancellationPending; i++)
            {
                writer.Track = tracks[i];
                writer.Write(stream);

                percentage = (i + 1f) / properties.TrackCount;

                saveWorker.ReportProgress((int)(100 * percentage));
            }

            if (saveWorker.CancellationPending)
            {
                e.Cancel = true;
            }
        }
    }
コード例 #10
0
        /// <summary>
        /// Snaps the point specified in endpoint of line to another line if within snapradius
        /// </summary>
        protected void SnapLineEnd(TrackWriter trk, GameLine line, Vector2d endpoint)
        {
            var ignore = new int[] { line.ID };

            GetSnapPoint(
                trk,
                line.Position,
                line.Position2,
                endpoint,
                ignore,
                out var snap,
                line is StandardLine);

            if (snap == endpoint)
            {
                return;
            }
            if (line.Position == endpoint)
            {
                // don't snap to the same point.
                if (line.Position2 != snap)
                {
                    trk.MoveLine(line, snap, line.Position2);
                }
            }
            else if (line.Position2 == endpoint)
            {
                // don't snap to the same point.
                if (line.Position != snap)
                {
                    trk.MoveLine(line, line.Position, snap);
                }
            }
        }
コード例 #11
0
 private void PlaceLines(TrackWriter trk, bool preview)
 {
     if (controlPoints.Count > 1)
     {
         List <Vector2> curvePoints = GameRenderer.GenerateBezierCurve(controlPoints.ToArray(), Settings.Bezier.Resolution).ToList();
         if (!preview)
         {
             game.Track.UndoManager.BeginAction();
         }
         for (int i = 1; i < curvePoints.Count; i++)
         {
             Vector2d _start = (Vector2d)curvePoints[i - 1];
             Vector2d _end   = (Vector2d)curvePoints[i];
             if ((_end - _start).Length >= MINIMUM_LINE)
             {
                 var added = CreateLine(trk, _start, _end, _addflip, Snapped, EnableSnap);
                 workingLines.Add(added);
             }
         }
         game.Track.NotifyTrackChanged();
         if (!preview)
         {
             game.Track.UndoManager.EndAction();
         }
     }
     game.Invalidate();
 }
コード例 #12
0
 private void updateFilenames(int Idx)
 {
     if (!isMultiple)
     {
         template.UpdateMainGroup();
         string[] ss = TrackWriter.GetRenames(template).Distinct().ToArray();
         cboRename.Items.Clear();
         cboRename.Items.AddRange(ss);
         cboRename.SelectedIndex = Idx;
     }
 }
コード例 #13
0
        private void UpdateLine(TrackWriter trk, GameLine current, GameLine replacement)
        {
            MakingChange();

            if (replacement is StandardLine stl)
            {
                stl.CalculateConstants();
            }
            trk.ReplaceLine(current, replacement);
            _editor.NotifyTrackChanged();
            _editor.Invalidate();
        }
コード例 #14
0
ファイル: Tool.cs プロジェクト: soni801/LRA-Community-Edition
        protected GameLine CreateLine(
            TrackWriter trk,
            Vector2d start,
            Vector2d end,
            bool inv,
            bool snapstart,
            bool snapend)
        {
            GameLine added = null;

            switch (Swatch.Selected)
            {
            case LineType.Blue:
                added = new StandardLine(start, end, inv);
                break;

            case LineType.Red:
                var red = new RedLine(start, end, inv)
                {
                    Multiplier = Swatch.RedMultiplier
                };
                red.CalculateConstants();    //multiplier needs to be recalculated
                added = red;
                break;

            case LineType.Scenery:
                added = new SceneryLine(start, end)
                {
                    Width = Swatch.GreenMultiplier
                };
                break;

            default:     //In case no swatch is chosen select blue and make a blue line
                added           = new StandardLine(start, end, inv);
                Swatch.Selected = LineType.Blue;
                break;
            }
            trk.AddLine(added);
            if (Swatch.Selected != LineType.Scenery)
            {
                if (snapstart)
                {
                    SnapLineEnd(trk, added, added.Position);
                }
                if (snapend)
                {
                    SnapLineEnd(trk, added, added.Position2);
                }
            }
            game.Track.Invalidate();
            return(added);
        }
コード例 #15
0
        private GameTrigger BeginModifyTrigger(TrackWriter trk)
        {
            var selected = SelectedTrigger;

            if (selected == -1)
            {
                return(null);
            }
            var trigger = trk.Triggers[selected];

            _trigger_copy = trigger.Clone();
            return(trigger);
        }
コード例 #16
0
        /// <summary>
        /// Gets lines near the point by radius.
        /// does not support large distances as it only gets a small number of grid cells
        /// </summary>
        /// <returns>a sorted array of lines where 0 is the closest point</returns>
        public GameLine[] LinesInRadius(TrackWriter trk, Vector2d position, double rad)
        {
            SortedList <int, GameLine> lines = new SortedList <int, GameLine>();
            var inrect =
                trk.GetLinesInRect(new DoubleRect(position - new Vector2d(24, 24), new Vector2d(24 * 2, 24 * 2)),
                                   false);
            var circle = Rendering.StaticRenderer.GenerateCircle(position.X, position.Y, rad, 8);

            var ends = LineEndsInRadius(trk, position, rad);

            foreach (var line in ends)
            {
                lines[line.ID] = line;
            }
            foreach (var line in inrect)
            {
                if (lines.ContainsKey(line.ID))
                {
                    continue;
                }
                var angle = Angle.FromLine(line.Position, line.Position2);
                var rect  = Utility.GetThickLine(
                    line.Position,
                    line.Position2,
                    angle,
                    line.Width * 2);
                if (Utility.PointInRectangle(rect, position))
                {
                    lines.Add(line.ID, line);
                    continue;
                }
                else
                {
                    for (int i = 0; i < circle.Length; i++)
                    {
                        if (Utility.PointInRectangle(rect, circle[i]))
                        {
                            lines.Add(line.ID, line);
                            break;
                        }
                    }
                }
            }
            GameLine[] ret = new GameLine[lines.Count];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = lines.Values[(lines.Count - 1) - i];
            }
            return(lines.Values.ToArray());
        }
コード例 #17
0
        protected GameLine CreateLine(
            TrackWriter trk,
            Vector2d start,
            Vector2d end,
            bool inv,
            bool snapstart,
            bool snapend)
        {
            GameLine added = null;

            switch (game.Canvas.ColorControls.Selected)
            {
            case LineType.Blue:
                added = new StandardLine(start, end, inv);
                break;

            case LineType.Red:
                var red = new RedLine(start, end, inv)
                {
                    Multiplier = game.Canvas.ColorControls.RedMultiplier
                };
                red.CalculateConstants();    //multiplier needs to be recalculated
                added = red;
                break;

            case LineType.Scenery:
                added = new SceneryLine(start, end)
                {
                    Width = game.Canvas.ColorControls.GreenMultiplier
                };
                break;
            }
            trk.AddLine(added);
            if (game.Canvas.ColorControls.Selected != LineType.Scenery)
            {
                if (snapstart)
                {
                    SnapLineEnd(trk, added, added.Position);
                }
                if (snapend)
                {
                    SnapLineEnd(trk, added, added.Position2);
                }
            }
            game.Track.Invalidate();
            return(added);
        }
コード例 #18
0
        private void EndModifyTrigger(GameTrigger trigger, TrackWriter trk)
        {
            var selected = SelectedTrigger;

            if (selected == -1)
            {
                throw new Exception(
                          "SelectedTrigger was removed during ModifyTrigger");
            }

            _changemade   = true;
            trigger.Start = (int)(_spinnerStart.Value);
            trigger.End   = (int)(_spinnerStart.Value + _spinnerDuration.Value);
            trk.Triggers[SelectedTrigger] = trigger;
            _editor.Timeline.TriggerChanged(_trigger_copy, trigger);
            UpdateFrame();
        }
コード例 #19
0
ファイル: Organizer.cs プロジェクト: usmanatron/quuxplayer
        private void updateSample()
        {
            renameFormat = TrackWriter.GetRenameFormat(cboRename.Text);
            dirFormat    = TrackWriter.GetDirFormat(cboSubdirectory.Text);

            if (pathIsValid(complexify(root())))
            {
                btnOK.Enabled = true;
                sampleText    = Path.Combine((root()), TrackWriter.GetPath(sampleTrack, dirFormat, renameFormat));// +sampleTrack.DefaultExtension;
            }
            else
            {
                sampleText    = invalidPath;
                btnOK.Enabled = false;
            }
            this.Invalidate();
        }
コード例 #20
0
        private void addLine(TrackWriter trk, Vector2d start, Vector2d end, LineType type, bool inv)
        {
            switch (type)
            {
            case LineType.Blue:
                lines.Add(CreateLine(trk, start, end, type, inv));
                break;

            case LineType.Red:
                lines.Add(CreateLine(trk, start, end, type, inv, multiplier));
                break;

            case LineType.Scenery:
                lines.Add(CreateLine(trk, start, end, type, inv, 1, width));
                break;
            }
        }
コード例 #21
0
        public bool Load()
        {
            if (!this.ConfirmExists)
            {
                return(false);
            }
            if (this.FileDate != File.GetLastWriteTime(this.FilePath))
            {
                this.toStringDirty     = true;
                this.searchStringDirty = true;

                TrackWriter.GetTags(this);

                FileInfo fi = new FileInfo(this.FilePath);
                this.FileSize = fi.Length;
                this.FileDate = fi.LastWriteTime;

                if (Setting.MoveNewFilesIntoMain)
                {
                    this.ChangeType  |= (ChangeType.Rename | ChangeType.Move | ChangeType.IgnoreContainment);
                    this.RenameFormat = Setting.DefaultRenameFormat;
                    TrackWriter.AddToUnsavedTracks(this);
                }
                else if (Setting.KeepOrganized)
                {
                    this.ChangeType  |= (ChangeType.Rename | ChangeType.Move);
                    this.RenameFormat = Setting.DefaultRenameFormat;
                    TrackWriter.AddToUnsavedTracks(this);
                }

                if (this.Type == FileType.None)
                {
                    return(false);
                }

                UpdateMainGroup();

                Database.IncrementDatabaseVersion(false);

                System.Threading.Thread.Sleep(0);
            }
            return(true);
        }
コード例 #22
0
        private void removeEpisode(PodcastEpisode PE)
        {
            List <frmTaskDialog.Option> options = new List <frmTaskDialog.Option>();

            if (PE.Playable || PE.IsDownloading) // only ask if there's already some data
            {
                options.Add(new frmTaskDialog.Option("Remove Podcast Entry", "Remove this episode from the episode list but leave the audio file in your library.", 1));
                options.Add(new frmTaskDialog.Option("Remove All", "Remove this episode from the list and delete the audio file.", 2));
                options.Add(new frmTaskDialog.Option("Cancel", "Don't remove this episode.", 0));

                frmTaskDialog od = new frmTaskDialog("Remove Podcast Episode",
                                                     "Choose an option for removing a podcast episode:",
                                                     options);

                od.ShowDialog(this);

                switch (od.ResultIndex)
                {
                case 0:
                    return;

                case 1:
                    break;

                case 2:
                    if (PE.Track != null)
                    {
                        Database.RemoveFromLibrary(new List <Track>()
                        {
                            PE.Track
                        });
                        TrackWriter.AddToDeleteList(PE.Track.FilePath);
                        TrackWriter.DeleteItems();
                        PE.Track = null;
                    }
                    break;
                }
            }
            PE.SetDownloadStatus(PodcastDownloadStatus.Deleted);
            lvwEpisodes.RemoveItem(PE);
        }
コード例 #23
0
        public static float GetReplayGain(Track Track, ReplayGainMode Type, bool FallBack)
        {
            if (Type == ReplayGainMode.Off)
            {
                return(0.0f);
            }

            switch (Type)
            {
            case ReplayGainMode.Album:
                if (!Track.HasReplayGainInfoAlbum)
                {
                    if (Track.HasReplayGainInfoTrack)
                    {
                        return(Track.ReplayGainTrack);
                    }
                    else
                    {
                        TrackWriter.LoadReplayGain(Track, BassTags.BASS_TAG_GetFromFile(Track.FilePath, true, false));
                    }
                }
                return(Track.ReplayGainAlbum);

            case ReplayGainMode.Track:
                if (!Track.HasReplayGainInfoTrack)
                {
                    if (Track.HasReplayGainInfoAlbum)
                    {
                        return(Track.ReplayGainAlbum);
                    }
                    else
                    {
                        TrackWriter.LoadReplayGain(Track, BassTags.BASS_TAG_GetFromFile(Track.FilePath, true, false));
                    }
                }
                return(Track.ReplayGainTrack);

            default:     // off
                return(0.0f);
            }
        }
コード例 #24
0
        public AudioStreamFile(Track Track,
                               float GainDB,
                               float[] Equalizer,
                               int NumEqBands,
                               bool EqualizerOn,
                               ReplayGainMode ReplayGain)
            : base(Track, GainDB, Equalizer, NumEqBands, EqualizerOn, ReplayGain)
        {
            this.filePath = track.FilePath;


            if (filePath != String.Empty)
            {
                Bass.BASS_Init(0, 0, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                streamRef = Bass.BASS_StreamCreateFile(filePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
            }

            setupChannelFromStream();

            TrackWriter.UpdateTrackInfo(track, info);
        }
コード例 #25
0
        public void AddToLibrary(String FilePath)
        {
            if (Track == null)
            {
                Track = Track.Load(FilePath);
            }
            if (Track == null)
            {
                this.DownloadStatus = PodcastDownloadStatus.Error;
                throw new Exception("failed");
            }
            Track.Title        = this.Title;
            Track.Album        = Subscription.Name;
            Track.Genre        = this.Subscription.DefaultGenre;
            Track.RenameFormat = TrackWriter.RenameFormat.AR_AL_TK_TI;
            TrackWriter.AddToUnsavedTracks(Track);

            Database.AddToLibrary(Track, true, false);

            TrackWriter.Start();
        }
コード例 #26
0
        /// <summary>
        /// Snaps the point specified in endpoint of line to another line if within snapradius
        /// </summary>
        protected void SnapLineEnd(TrackWriter trk, GameLine line, Vector2d endpoint)
        {
            var lines = LineEndsInRadius(trk, endpoint, SnapRadius);

            for (int i = 0; i < lines.Length; i++)
            {
                var curr = lines[i];
                if (curr != line)
                {
                    if (line is StandardLine && curr is SceneryLine)
                    {
                        continue;//phys lines dont wanna snap to scenery
                    }
                    var snap = Utility.CloserPoint(endpoint, curr.Position, curr.Position2);
                    if (line.Position == endpoint)
                    {
                        // don't snap to the same point.
                        if (line.Position2 != snap)
                        {
                            trk.MoveLine(line, snap, line.Position2);
                        }
                    }
                    else if (line.Position2 == endpoint)
                    {
                        // don't snap to the same point.
                        if (line.Position != snap)
                        {
                            trk.MoveLine(line, line.Position, snap);
                        }
                    }
                    else
                    {
                        throw new Exception("Endpoint does not match line position in snap. It's not one of the ends of the line.");
                    }
                    break;
                }
            }
        }
コード例 #27
0
        protected GameLine CreateLine( //Creates a line from a pair of vectors (modified from Tool.cs)
            TrackWriter trk,
            Vector2d start,
            Vector2d end,
            LineType type,
            bool inv,
            int multiplier = 1,    //Only applies to red lines (smh)
            float width    = 1.0f) //Width only applicable to green lines
        {
            GameLine added = null;

            switch (type)
            {
            case LineType.Blue:
                added = new StandardLine(start, end, inv);
                break;

            case LineType.Red:
                var red = new RedLine(start, end, inv)
                {
                    Multiplier = multiplier
                };
                red.CalculateConstants();    //multiplier needs to be recalculated
                added = red;
                break;

            case LineType.Scenery:
                added = new SceneryLine(start, end)
                {
                    Width = width
                };
                break;
            }
            trk.AddLine(added);
            game.Track.Invalidate();
            return(added);
        }
コード例 #28
0
        private void setupRename(string Caption, bool MakeCheckbox)
        {
            cboRename = new QComboBox(false, Styles.FontSmaller);
            setupControl(cboRename, Caption, MakeCheckbox);

            if (isMultiple)
            {
                string[] ss = TrackWriter.GetRenames().ToArray();
                cboRename.Items.AddRange(ss);
                cboRename.SelectedIndex = 0; // cboRename.FindStringExact(ss[0]);
                cboRename.LostFocus    += (s, e) =>
                {
                    if (cboRename.Text.Length == 0)
                    {
                        checkboxes[cboRename].Checked = false;
                    }
                };
                cboRename.EnableWatermark(this, MULTIPLE_VALUES, MULTIPLE_VALUES);
            }
            else
            {
                updateFilenames(0);
            }
        }
コード例 #29
0
        public void Download()
        {
            cancelAllDownloads = false;
            cancelThisDownload = false;
            if (this.FileExists)
            {
                if (this.DownloadStatus != PodcastDownloadStatus.Played)
                {
                    this.DownloadStatus = PodcastDownloadStatus.Unplayed;
                }
            }
            else
            {
                using (WebClient client = new WebClient())
                {
                    this.DownloadStatus = PodcastDownloadStatus.DownloadInProgress;
                    updateDownloadStatusString();

                    Stream          localStream   = null;
                    Stream          resposeStream = null;
                    HttpWebRequest  webRequest    = null;
                    HttpWebResponse webResponse   = null;

                    try
                    {
                        long totalSize = 1;

                        string localTempFile = Path.GetTempFileName();

                        webRequest             = (HttpWebRequest)WebRequest.Create(this.URL);
                        webRequest.Credentials = CredentialCache.DefaultCredentials;
                        webRequest.ServicePoint.Expect100Continue = false;
                        webResponse   = (HttpWebResponse)webRequest.GetResponse();
                        totalSize     = webResponse.ContentLength;
                        resposeStream = client.OpenRead(this.URL);
                        localStream   = new FileStream(localTempFile,
                                                       FileMode.Create,
                                                       FileAccess.Write,
                                                       FileShare.None);

                        bool   showProgress  = totalSize > 100000;
                        int    chunkSize     = 0;
                        long   bytesRecd     = 0;
                        long   nextThreshold = 0;
                        byte[] downBuffer    = new byte[2048];

                        while ((chunkSize = resposeStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
                        {
                            if (cancelAllDownloads || cancelThisDownload)
                            {
                                this.DownloadStatus = PodcastDownloadStatus.DownloadCanceled;
                                return;
                            }
                            if (showProgress)
                            {
                                bytesRecd += chunkSize;
                                if (bytesRecd > nextThreshold)
                                {
                                    nextThreshold += totalSize / NUM_DOWNLOAD_UPDATES;
                                    updateDownloadStatusString("Downloading: " + (bytesRecd * 100L / totalSize).ToString() + "%");
                                }
                            }
                            localStream.Write(downBuffer, 0, chunkSize);
                        }

                        localStream.Close();
                        localStream = null;

                        if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                        {
                            try
                            {
                                Directory.CreateDirectory(Setting.PodcastDownloadDirectory);
                            }
                            catch
                            {
                            }
                            if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                            {
                                Setting.PodcastDownloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                                if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                                {
                                    Directory.CreateDirectory(Setting.PodcastDownloadDirectory);
                                }
                            }
                        }
                        if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                        {
                            throw new Exception("failed2");
                        }
                        string fileName    = Lib.ReplaceBadFilenameChars(this.Subscription.Name + " - " + this.Title);
                        string newPathRoot = Path.Combine(Setting.PodcastDownloadDirectory, fileName);
                        string ext         = Path.GetExtension(this.URL);

                        string newPath = newPathRoot + ext;
                        if (File.Exists(newPath))
                        {
                            int i = 1;
                            do
                            {
                                newPath = newPathRoot + (i++).ToString() + ext;
                            }while (File.Exists(newPath));
                        }

                        File.Copy(localTempFile, newPath);
                        TrackWriter.AddToDeleteList(localTempFile);
                        TrackWriter.DeleteItems();

                        AddToLibrary(newPath);

                        fileExists = null;

                        this.DownloadStatus = PodcastDownloadStatus.Unplayed;
                        this.DownloadDate   = DateTime.Now;
                        if (this.DownloadDate > this.Subscription.LastDownloadDate)
                        {
                            this.Subscription.LastDownloadDate = this.DownloadDate;
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                        this.DownloadStatus = PodcastDownloadStatus.Error;
                        Controller.ShowMessage("Download of " + this.Title + " failed.");
                    }
                    finally
                    {
                        if (localStream != null)
                        {
                            localStream.Close();
                        }
                        if (resposeStream != null)
                        {
                            resposeStream.Close();
                        }
                        if (webResponse != null)
                        {
                            webResponse.Close();
                        }

                        updateDownloadStatusString();
                    }
                }
            }
            System.Diagnostics.Debug.Assert(!this.IsDownloading);
            if (DataChanged != null)
            {
                DataChanged(this);
            }
        }
コード例 #30
0
        public void Close()
        {
            exiting = true;

            Lib.EnableNavKeys(true);
            normal.RemoveFilterIndex();

            Crawler.Stop();
            TrackWriter.Stop();

            if (rg != null)
            {
                rg.Cancel();
            }

            iTunes.Cancel = true;

            if (notifyIcon != null)
            {
                notifyIcon.Visible = false;
                notifyIcon         = null;
            }

            if (normal.Queue.Reordered && normal.Queue.PlaylistBasis.Length > 0 && (Database.GetPlaylistType(normal.Queue.PlaylistBasis) == PlaylistType.Standard))
            {
                Database.SaveStandardPlaylist(normal.Queue);
            }

            player.Dispose();

            Database.SaveSetting(SettingType.ShowSpectrumGrid, spectrumView.ShowGrid);
            Database.SaveSetting(SettingType.SpectrumGain, spectrumView.Gain);
            Database.SaveSetting(SettingType.ViewMode, (HTPCMode == HTPCMode.Normal ? "Normal" : "HTPC"));
            Database.SaveSetting(SettingType.CurrentFilter, normal.CurrentFilterName);
            Database.SaveSetting(SettingType.DecoderGain, DecoderGainDB);
            Database.SaveSetting(SettingType.ColumnStatus, normal.SerializeColumnStatus(HTPCMode.Normal));
            Database.SaveSetting(SettingType.ColumnStatusHTPC, normal.SerializeColumnStatus(HTPCMode.HTPC));
            Database.SaveSetting(SettingType.AskAboutMissingFiles, askAboutMissingFiles);
            Database.SaveSetting(SettingType.EqualizerOn, equalizer.On);
            Database.SaveSetting(SettingType.EqualizerTenBands, equalizer.NumBands == 10);
            Database.SaveSetting(SettingType.EqualizerFineControl, equalizer.FineControl);
            Database.SaveSetting(SettingType.CurrentEqualizer, equalizer.CurrentEqualizer.Name);
            Database.SaveSetting(SettingType.DownloadAlbumCovers, Track.DownloadCoverArt);
            Database.SaveSetting(SettingType.UseGlobalHotKeys, UseGlobalHotKeys);
            Database.SaveSetting(SettingType.FullScreen, Lib.FullScreen || !Lib.ManualReleaseFullScreen);
            Database.SaveSetting(SettingType.SpectrumSmall, (player.SpectrumMode == SpectrumMode.Small));
            Database.SaveSetting(SettingType.ArtSave, (int)ArtSaveOption);
            Database.SaveSetting(SettingType.TwitterOn, Twitter.On);
            Database.SaveSetting(SettingType.TwitterUserName, Twitter.UserName);
            Database.SaveSetting(SettingType.TwitterPassword, Twitter.Password);

            Database.SaveSetting(SettingType.LocalVolumeControlOnly, LocalVolumeControl);
            Database.SaveSetting(SettingType.LocalVolumeLevel, localVolumeLevel);
            Database.SaveSetting(SettingType.RunNumber, runNumber);
            Database.SaveSetting(SettingType.OutputDeviceName, player.OutputDeviceName);
            Database.SaveSetting(SettingType.TwitterMode, (int)Twitter.TwitterMode);
            Database.SaveSetting(SettingType.TagCloudMaxItems, tagCloud.MaxItems);
            Database.SaveSetting(SettingType.TagCloudColor, tagCloud.UseColor);
            Setting.Save();

            System.Drawing.Rectangle r;
            if (!Lib.FullScreen && mainForm.WindowState == FormWindowState.Normal)
            {
                r = mainForm.Bounds;
            }
            else
            {
                r = System.Drawing.Rectangle.Empty;
            }

            Database.SaveSetting(SettingType.NormalWindowBoundsX, r.X);
            Database.SaveSetting(SettingType.NormalWindowBoundsY, r.Y);
            Database.SaveSetting(SettingType.NormalWindowBoundsWidth, r.Width);
            Database.SaveSetting(SettingType.NormalWindowBoundsHeight, r.Height);

            Database.SaveSetting(SettingType.LastFMOn, lastFMOn);
            Database.SaveSetting(SettingType.LastFMUserName, lastFMUserName);
            Database.SaveSetting(SettingType.LastFMPassword, lastFMPassword);

            Database.SaveSetting(SettingType.MiniPlayerXPos, frmMiniPlayer.DefaultLocation.X);
            Database.SaveSetting(SettingType.MiniPlayerYPos, frmMiniPlayer.DefaultLocation.Y);

            Database.Close(mainForm);

            Clock.DoOnNewThreadNotBackground(TrackWriter.DeleteItemsLastChance);

            Clock.Close();
        }