public void Load([NotNull] string musicFileName, [CanBeNull] out string errorMessageTemplate)
            {
                errorMessageTemplate = null;

                if (File.Exists(musicFileName))
                {
                    try {
                        _liveFileStream = File.Open(musicFileName, FileMode.Open, FileAccess.Read);
                        _liveWaveStream = LiveMusicWaveStream.FromWaveStream(_liveFileStream);

                        _liveMusicPlayer = new LiveMusicPlayer(_audioManager);
                        _liveMusicPlayer.LoadStream(_liveWaveStream);
                    } catch (IOException) {
                        errorMessageTemplate = LanguageManager.TryGetString("messages.fmain.live_music_open_error_template") ?? "Cannot open '{0}'. Live music disabled.";
                    }
                }
                else
                {
                    errorMessageTemplate = LanguageManager.TryGetString("messages.fmain.live_music_not_found_template") ?? "File '{0}' does not exist. Live music disabled.";
                }
            }
Esempio n. 2
0
        private void BtnScoreLoad_Click(object sender, EventArgs e)
        {
            if (!CheckPlayEnvironment())
            {
                return;
            }
            var audioFileName      = txtAudioFileName.Text;
            var audioFileInfo      = new FileInfo(audioFileName);
            var audioFileExtension = audioFileInfo.Extension.ToLowerInvariant();

            if (audioFileExtension == ExtensionAcb)
            {
                _audioFileStream = File.Open(audioFileName, FileMode.Open, FileAccess.Read);
                _musicWaveStream = LiveMusicWaveStream.FromAcbStream(_audioFileStream, audioFileName, DefaultCgssDecodeParams);
                PlayerSettings.MusicFileOffset = TimeSpan.Zero;
            }
            else if (audioFileExtension == ExtensionWav)
            {
                _audioFileStream = File.Open(audioFileName, FileMode.Open, FileAccess.Read);
                _musicWaveStream = LiveMusicWaveStream.FromWaveStream(_audioFileStream);
                PlayerSettings.MusicFileOffset = TimeSpan.FromSeconds(
                    (double)HcaEncoderInfo.EncoderDelayInSamples / _musicWaveStream.WaveFormat.SampleRate);
            }
            else if (audioFileExtension == ExtensionHca)
            {
                _audioFileStream = File.Open(audioFileName, FileMode.Open, FileAccess.Read);
                _musicWaveStream = LiveMusicWaveStream.FromHcaStream(_audioFileStream, DefaultCgssDecodeParams);
                PlayerSettings.MusicFileOffset = TimeSpan.Zero;
            }
            else
            {
                throw new ArgumentOutOfRangeException(nameof(audioFileExtension), $"Unsupported audio format: '{audioFileExtension}'.");
            }
            _scorePlayer = new ScorePlayer();
            _scorePlayer.PlaybackStopped += MusicPlayer_PlaybackStopped;
            _scorePlayer.AddInputStream(_musicWaveStream, PlayerSettings.MusicVolume);
            _sfxManager = new SfxManager(_scorePlayer);
            PreloadNoteSounds();
            _sfxBufferTime = 0d;
            _scorePlayer.PositionChanged += MusicPlayer_PositionChanged;
            var sfxDirName = string.Format(SoundEffectAudioDirectoryNameFormat, cboSoundEffect.SelectedIndex.ToString("00"));

            _currentTapHcaFileName   = $"{sfxDirName}/{TapHcaName}";
            _currentFlickHcaFileName = $"{sfxDirName}/{FlickHcaName}";
            Score score;
            var   scoreFileName      = txtScoreFileName.Text;
            var   scoreFileExtension = new FileInfo(scoreFileName).Extension.ToLowerInvariant();

            if (scoreFileExtension == ExtensionBdb)
            {
                score = Score.FromBdbFile(scoreFileName, (Difficulty)(cboDifficulty.SelectedIndex + 1));
            }
            else if (scoreFileExtension == ExtensionCsv)
            {
                score = Score.FromCsvFile(scoreFileName);
            }
            else
            {
                throw new ArgumentException("What?", nameof(scoreFileExtension));
            }
            _score       = score;
            editor.Score = _score;
            SetControlsEnabled(ViewerState.Loaded);
            lblSong.Text = string.Format(SongTipFormat, _musicWaveStream.HcaName);
            timer.Start();
        }