public EqualizerViewModel(Equalizer equalizer)
        {
            this.Equalizer = equalizer;

            SetToDefaultCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Equalizer.IsEnabled));
            SetToDefaultCommand.Subscribe(_ => Equalizer.SetToDefault());

            CloseEqualizerCommand = ReactiveCommand.Create();
            CloseEqualizerCommand.Subscribe(_ => {
                if (this.Equalizer.IsEnabled)
                {
                    this.Equalizer.SaveEqualizerSettings();
                }
            });
        }
        internal bool ConfigureInternal()
        {
            try
            {
                this.Initializied = false;

                // Global Settings
                if (!Factory.System_Create(out this.system).ERRCHECK())
                {
                    return(false);
                }

                uint version;
                this.system.getVersion(out version).ERRCHECK();
                if (version < VERSION.number)
                {
                    return(false);
                }

                if (!this.system.init(16, INITFLAGS.NORMAL, (IntPtr)null).ERRCHECK())
                {
                    return(false);
                }

                if (!this.system.setStreamBufferSize(64 * 1024, TIMEUNIT.RAWBYTES).ERRCHECK())
                {
                    return(false);
                }

                // equalizer
                this.Equalizer = Equalizer.GetEqualizer(this.system, this.playerSettings);

                this.Volume   = this.playerSettings.PlayerEngine.Volume;
                this.IsMute   = this.playerSettings.PlayerEngine.Mute;
                this.State    = PlayerState.Stop;
                this.LengthMs = 0;

                this.WhenAnyValue(x => x.Volume)
                .Subscribe(newVolume => {
                    this.playerSettings.PlayerEngine.Volume = newVolume;

                    ChannelGroup masterChannelGroup;
                    this.system.getMasterChannelGroup(out masterChannelGroup).ERRCHECK();
                    masterChannelGroup.setVolume(newVolume / 100f).ERRCHECK();
                    this.system.update().ERRCHECK();
                });

                this.WhenAnyValue(x => x.IsMute)
                .Subscribe(mute => {
                    this.playerSettings.PlayerEngine.Mute = mute;

                    ChannelGroup masterChannelGroup;
                    this.system.getMasterChannelGroup(out masterChannelGroup).ERRCHECK();
                    masterChannelGroup.setMute(mute).ERRCHECK(FMOD.RESULT.ERR_INVALID_HANDLE);
                    this.system.update().ERRCHECK();
                });

                var canSetCurrentPosition = this.WhenAny(x => x.CanSetCurrentPositionMs, y => y.LengthMs,
                                                         (dontUpdate, length) => dontUpdate.Value && length.Value > 0);
                this.SetCurrentPositionMs = ReactiveCommand.Create(canSetCurrentPosition);
                this.SetCurrentPositionMs.Subscribe(x => {
                    var newPos = this.CurrentPositionMs >= this.LengthMs ? this.LengthMs - 1 : this.CurrentPositionMs;
                    if (this.channelInfo != null)
                    {
                        this.channelInfo.SetCurrentPositionMs(newPos);
                    }
                    this.CanSetCurrentPositionMs = false;
                });

                this.timer = new DispatcherTimer(TimeSpan.FromMilliseconds(10),
                                                 DispatcherPriority.Normal,
                                                 this.PlayTimerCallback,
                                                 Application.Current.Dispatcher);
                this.timer.Stop();

                this.Initializied = true;

                return(true);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception);
                return(false);
            }
        }
예제 #3
0
 public static Equalizer GetEqualizer(FMOD.System system, PlayerSettings settings)
 {
     var eq = new Equalizer(system, settings);
     eq.Initializied = true;
     return eq;
 }