Beispiel #1
0
        public void TuneEndWithinDesktopViewRange()
        {
            //         |-----------|
            //   |=====|=====|     |
            //  400   500   600   700
            //
            var window = new Range(500, 700);
            var tune = new Tune(_mockFrameData.Object) { StartTick = 400 };

            var firstVisibleTuneTick = Math.Max(window.Minimum, tune.StartTick);
            Assert.Equal(500, firstVisibleTuneTick);

            var lastVisibleTuneTick = Math.Min(window.Maximum, tune.EndTick);
            Assert.Equal(600, lastVisibleTuneTick);

            var offsetIntoTune = Math.Max(0, window.Minimum - tune.StartTick);
            Assert.Equal(100, offsetIntoTune);

            var visibleTicks = Math.Min(window.Width, Math.Min(window.Maximum - tune.StartTick, tune.EndTick - window.Minimum));
            Assert.Equal(100, visibleTicks);
        }
Beispiel #2
0
        public void TuneStraddlesDesktopViewRange()
        {
            //        |-----|-----|
            //  |=====|===========|=====|
            // 400   500         700   800

            _mockFrameData.Setup(f => f.Length).Returns(400);

            var window = new Range(500, 700);
            var tune = new Tune(_mockFrameData.Object) { StartTick = 400 };

            var firstVisibleTuneTick = Math.Max(window.Minimum, tune.StartTick);
            Assert.Equal(500, firstVisibleTuneTick);

            var lastVisibleTuneTick = Math.Min(window.Maximum, tune.EndTick);
            Assert.Equal(700, lastVisibleTuneTick);

            var offsetIntoTune = Math.Max(0, window.Minimum - tune.StartTick);
            Assert.Equal(100, offsetIntoTune);

            var visibleTicks = Math.Min(window.Width, Math.Min(window.Maximum - tune.StartTick, tune.EndTick - window.Minimum));
            Assert.Equal(200, visibleTicks);
        }
Beispiel #3
0
        private void On_Load()
        {
            _tunes = new List<Tune>();

            //var p = new Project { TuneFilenames = new[] { "abc", "def" } };
            //string x = JsonConvert.SerializeObject(p);

            var fileConverterFactory = new FileConverterFactory(new FileSystemHelper());

            try
            {
                var project = Project.OpenProject(Path.Combine(Directory.GetCurrentDirectory(), "TestProject"));

                foreach (var fileName in project.TuneFilenames)
                {
                    var metaDataPath = Path.Combine(project.WorkingFolder, "MetaData");
                    Directory.CreateDirectory(metaDataPath);

                    var tunePath = Path.Combine(project.WorkingFolder, fileName);

                    var rawTunePath = Path.ChangeExtension(Path.Combine(metaDataPath, fileName), "m6raw");
                    var summaryPath = Path.ChangeExtension(Path.Combine(metaDataPath, fileName), "summary");

                    IFileConverter converter;
                    if ((converter = fileConverterFactory.ParseFile(rawTunePath)) == null)
                    {
                        converter = fileConverterFactory.ParseFile(tunePath);
                    }
                    if (converter == null) continue;

                    var waveData = converter.ProcessFile();
                    if (waveData == null) continue;

                    if (!File.Exists(rawTunePath))
                    {
                        try
                        {
                            using (var rawFile = File.Create(rawTunePath))
                            {
                                Serializer.Serialize(rawFile, waveData);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    var tune = new Tune(waveData);

                    SummaryCollection summaryData = null;
                    try
                    {
                        using (var summaryFile = File.OpenRead(summaryPath))
                        {
                            summaryData = Serializer.Deserialize<SummaryCollection>(summaryFile);
                        }

                        tune.SummaryCollection = summaryData;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    if (summaryData == null)
                    {
                        tune.BuildSummaries();
                        try
                        {
                            using (var summaryFile = File.Create(summaryPath))
                            {
                                Serializer.Serialize(summaryFile, tune.SummaryCollection);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }

                    tune.StartTick = 0;
                    tune.Track = _tunes.Count;

                    _tunes.Add(tune);
                }

                _delta = new Delta();

                _ticksPerPixel = 1024;

                _bbBitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);

                _desktopRange = new Range(0, ClientRectangle.Width*_ticksPerPixel);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #4
0
        private void On_MouseDown(MouseEventArgs e)
        {
            _leftButtonDown = true;
            _delta.Reset(e.Location);

            var clickedTick = _desktopRange.Minimum + e.Location.X * _ticksPerPixel;

            _selectedTune = _tunes.FirstOrDefault(tune => tune.TickRange.ContainsValue(clickedTick) && new Range(100 + tune.Track * 260, 100 + (tune.Track + 1) * 260).ContainsValue(e.Location.Y));

            if (_selectedTune == null)
            {
                _playCursor = clickedTick;
            }

            Invalidate();
        }
Beispiel #5
0
        public void TuneNotInRange(int startTick)
        {
            //               |-----|
            //   |=====|     |     |     |=====|
            //  400   500   600   700   800   900
            //

            _mockFrameData.Setup(f => f.Length).Returns(100);

            var window = new Range(600, 700);
            var tune = new Tune(_mockFrameData.Object) { StartTick = startTick };

            var visibleTicks = Math.Min(window.Width, Math.Min(window.Maximum - tune.StartTick, tune.EndTick - window.Minimum));
            Assert.Equal(-100, visibleTicks);
        }