コード例 #1
0
        public DrumKitTabViewModel(IEventAggregator eventAggregator, IDialogCoordinator dialogCoordinator)
            : base(eventAggregator, dialogCoordinator, new DrumKitPatchManager())
        {
            DisplayName = "Drums";
            InitLogger(typeof(DrumKitTabViewModel));

            Patch  = new Patch();
            Editor = new DrumKitPartialEditorViewModel(Patch);

            // TODO: AutoSync dumping
            Patch.PropertyChanged += (sender, args) =>
            {
                if (AutoSync && SelectedOutputDeviceId != -1)
                {
                    var drumPatchManager = (IDrumKitPatchManager)PatchManager;

                    if (args.PropertyName == nameof(Patch.Common))
                    {
                        drumPatchManager.DumpCommon(Patch.Common, SelectedOutputDeviceId);
                    }
                    else
                    {
                        var key = (DrumKey)Enum.Parse(typeof(DrumKey), args.PropertyName);
                        drumPatchManager.DumpPartial(Patch.Partials[key], SelectedOutputDeviceId);
                    }

                    Logger.AutoSync($"{args.PropertyName} changed");
                }
            };

            PatchManager.DataDumpReceived += (sender, args) =>
            {
                if (args is DrumKitPatchDumpReceivedEventArgs eventArgs)
                {
                    AutoSync = false;

                    Patch.CopyFrom(eventArgs.Patch);
                    Logger.DataDump("Received data dump");

                    AutoSync = true;
                }
            };

            PatchManager.OperationTimedOut += (sender, args) =>
            {
                Logger.Error("Device is not responding");
                ShowErrorMessage("Device is not responding, try again in a moment");
            };
        }
コード例 #2
0
        /// <inheritdoc />
        /// <summary>
        ///     Creates new instance of AnalogSynthTabViewModel
        /// </summary>
        // ReSharper disable once SuggestBaseTypeForParameter
        public AnalogSynthTabViewModel(IEventAggregator eventAggregator, IDialogCoordinator dialogCoordinator)
            : base(eventAggregator, dialogCoordinator, new AnalogPatchManager())
        {
            DisplayName = "Analog Synth";
            InitLogger(typeof(AnalogSynthTabViewModel));

            Patch = new Patch();

            Patch.PropertyChanged += (sender, args) =>
            {
                if (AutoSync)
                {
                    Dump();
                    Logger.AutoSync($"{args.PropertyName} changed");
                }

                if (args.PropertyName == nameof(Patch.Oscillator))
                {
                    NotifyOfPropertyChange(nameof(IsPulseWidthEnabled));
                }
            };

            PatchManager.DataDumpReceived += (sender, args) =>
            {
                if (args is AnalogPatchDumpReceivedEventArgs eventArgs)
                {
                    AutoSync = false;

                    Patch.CopyFrom(eventArgs.Patch);
                    Logger.DataDump("Received data dump");

                    AutoSync = true;
                }
            };

            PatchManager.OperationTimedOut += (sender, args) =>
            {
                Logger.Error("Device is not responding");
                ShowErrorMessage("Device is not responding, try again in a moment");
            };
        }
コード例 #3
0
        /// <inheritdoc />
        /// <summary>
        ///     Creates new instance of DigitalSynthTabViewModel
        /// </summary>
        public DigitalSynthTabViewModel(IEventAggregator eventAggregator, IDialogCoordinator dialogCoordinator, DigitalSynth synth)
            : base(eventAggregator, dialogCoordinator, new DigitalPatchManager(synth))
        {
            //TODO: Take use of enum description
            DisplayName = synth == DigitalSynth.First ? "Digital Synth 1" : "Digital Synth 2";
            InitLogger(typeof(DigitalSynthTabViewModel));

            Patch  = new Patch();
            Editor = new DigitalPartialsEditorViewModel(Patch);

            Patch.PropertyChanged += (sender, args) =>
            {
                if (AutoSync && SelectedOutputDeviceId != -1)
                {
                    var digitalPatchManager = (IDigitalPatchManager)PatchManager;

                    switch (args.PropertyName)
                    {
                    case nameof(Patch.Common):
                        digitalPatchManager.DumpCommon(Patch.Common, SelectedOutputDeviceId);
                        break;

                    case nameof(Patch.Modifiers):
                        digitalPatchManager.DumpModifiers(Patch.Modifiers, SelectedOutputDeviceId);
                        break;

                    case nameof(Patch.PartialOne):
                        digitalPatchManager.DumpPartial(Patch.PartialOne, DigitalPartial.First,
                                                        SelectedOutputDeviceId);
                        break;

                    case nameof(Patch.PartialTwo):
                        digitalPatchManager.DumpPartial(Patch.PartialTwo, DigitalPartial.Second,
                                                        SelectedOutputDeviceId);
                        break;

                    case nameof(Patch.PartialThree):
                        digitalPatchManager.DumpPartial(Patch.PartialThree, DigitalPartial.Third,
                                                        SelectedOutputDeviceId);
                        break;
                    }

                    Logger.AutoSync($"{args.PropertyName} changed");
                }

                if (args.PropertyName == nameof(Modifiers))
                {
                    NotifyOfPropertyChange(nameof(IsEnvelopeLoopSyncNoteEnabled));
                }
            };

            PatchManager.DataDumpReceived += (sender, args) =>
            {
                if (args is DigitalPatchDumpReceivedEventArgs eventArgs)
                {
                    AutoSync = false;

                    Patch.CopyFrom(eventArgs.Patch);
                    Logger.DataDump("Received data dump");

                    AutoSync = true;
                }
            };

            PatchManager.OperationTimedOut += (sender, args) =>
            {
                Logger.Error("Device is not responding");
                ShowErrorMessage("Device is not responding, try again in a moment");
            };
        }