Ejemplo n.º 1
0
        private void timerAnimation_Tick(object sender, EventArgs e)
        {
            if (music == null)
            {
                return;
            }

            if (State == PlayerState.FF || State == PlayerState.REWIND)
            {
                var elapsed = (float)rewindStopwatch.Elapsed.TotalSeconds;
                rewindStopwatch.Restart();

                var pos        = music.GetCurrentPositionSeconds();
                var timeOffset = cassetteControl.AngularToLinear(State == PlayerState.FF, pos, elapsed * 360 * 5);
                timeOffset *= (State == PlayerState.REWIND) ? -1 : 1;
                music.SetCurrentPositionSeconds(pos + timeOffset);
            }

            cassetteControl.HeadEngaged   = State == PlayerState.PLAYING || State == PlayerState.RECORDING;
            cassetteControl.RollerEngaged = (State == PlayerState.PLAYING || State == PlayerState.RECORDING) && !isTapePaused;
            cassetteControl.AnimateSpools(music.GetCurrentPositionSeconds());

            counter.SetPosition(-cassetteControl.GetSpoolAngleDegrees(false, music.GetCurrentPositionSeconds()) / 360 / 2);

            if ((State == PlayerState.FF ||
                 State == PlayerState.REWIND ||
                 (State == PlayerState.RECORDING && !isPauseFullyPressed) ||
                 (State == PlayerState.PLAYING && !isPauseFullyPressed))
                &&
                music.IsAtBeginningOrEnd())
            {
                if (!autoStopStopwatch.IsRunning)
                {
                    autoStopStopwatch.Restart();
                }
                else if (autoStopStopwatch.Elapsed.TotalSeconds >= 4.0)
                {
                    autoStopStopwatch.Stop();

                    DisengageButtons();
                    State = PlayerState.STOPPED;
                    cassetteButtons.Invalidate();
                }
            }
            else
            {
                autoStopStopwatch.Stop();
            }
        }
Ejemplo n.º 2
0
        private void LoadTapeSide(TapeSide tapeSide)
        {
            string path = Path.Combine(tapeManager.TapesDirectory, tapeSide.FilePath);

            if (music != null && loadedTapeSide != null)
            {
                loadedTapeSide.Position = music.GetCurrentPositionSeconds();
            }

            mixer.RemoveSample(music);
            music?.wavFile.Close();

            WAVFile wav = new WAVFile(); //default value in case of error

            try
            {
                wav = WAVFile.Load(path);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error while loading tape", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            music = new SoundMixer.Sample(wav, false, false, false, 0.2f, 1.0f);
            mixer.AddSample(music);
            mixer.SetRecordingSample(music);

            loadedTapeSide = tapeSide;
            music.SetCurrentPositionSeconds(tapeSide.Position);

            State = PlayerState.STOPPED;
            cassetteControl.LoadedTapeSide = tapeSide;
            cassetteButtons.Enabled        = true;

            counter.IgnoreNextSetPosition();

            cassetteClose.UpdatePlayback(true);
        }