コード例 #1
0
        public async Task <bool> SetColor(int deviceId, ARGBB color)
        {
            var        device = dbContext.Device.Single(x => x.Id == deviceId);
            HttpClient client = await GetHttpClient(device.Ip);

            var result = await client.PostAsync("rgb", await DataToStringContent(color));

            if (result.IsSuccessStatusCode)
            {
                var colorHistory = new ColorHistory()
                {
                    DeviceId   = device.Id,
                    Red        = color.Red,
                    Green      = color.Green,
                    Blue       = color.Blue,
                    Brightness = color.Brightness,
                    Date       = DateTime.Now
                };
                dbContext.ColorHistory.Add(colorHistory);
                await dbContext.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
コード例 #2
0
 private void ColorHistory_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (!_loadingColorsHistory)
     {
         var settings = _settingsUtils.GetSettingsOrDefault <ColorPickerSettings>(ColorPickerModuleName);
         settings.Properties.ColorHistory = ColorHistory.ToList();
         settings.Save(_settingsUtils);
     }
 }
コード例 #3
0
ファイル: Encoder.cs プロジェクト: Gardinex/apollo-studio
        public static MemoryStream EncodePreferences()
        {
            MemoryStream output = new MemoryStream();

            using (BinaryWriter writer = new BinaryWriter(output)) {
                EncodeHeader(writer);
                EncodeID(writer, typeof(Preferences));

                writer.Write(Preferences.AlwaysOnTop);
                writer.Write(Preferences.CenterTrackContents);
                writer.Write((int)Preferences.LaunchpadStyle);
                writer.Write(Preferences.AutoCreateKeyFilter);
                writer.Write(Preferences.AutoCreatePageFilter);
                writer.Write(Preferences.AutoCreatePattern);
                writer.Write(Preferences.FadeSmoothnessSlider);
                writer.Write(Preferences.CopyPreviousFrame);
                writer.Write(Preferences.CaptureLaunchpad);
                writer.Write(Preferences.EnableGestures);
                writer.Write(Preferences.PaletteName);

                for (int i = 0; i < 128; i++)
                {
                    Encode(writer, Preferences.CustomPalette.BackingArray[i]);
                }

                writer.Write((int)Preferences.ImportPalette);
                writer.Write((int)Preferences.Theme);
                writer.Write(Preferences.Backup);
                writer.Write(Preferences.Autosave);
                writer.Write(Preferences.UndoLimit);
                writer.Write(Preferences.DiscordPresence);
                writer.Write(Preferences.DiscordFilename);

                int count = Math.Min(64, ColorHistory.Count);
                writer.Write(count);
                for (int i = 0; i < count; i++)
                {
                    Encode(writer, ColorHistory.GetColor(i));
                }

                writer.Write(MIDI.Devices.Count);
                for (int i = 0; i < MIDI.Devices.Count; i++)
                {
                    if (MIDI.Devices[i].GetType() == typeof(Launchpad))
                    {
                        Encode(writer, MIDI.Devices[i]);
                    }
                }
            }

            return(output);
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: vincent-deng/ColorWanted
        /// <summary>
        /// 复制HEX颜色值  双击复制RGB颜色值
        /// </summary>
        private void CopyColor(bool doubleClick)
        {
            try
            {
                ColorHistory.Record(ColorUtil.GetColor(MousePosition));
                var result = Util.SetClipboard(Handle, doubleClick ?
                                               (trayMenuCopyPolicyRgbValueOnly.Checked ? lbRgb.Tag.ToString() : lbRgb.Text) :
                                               (trayMenuCopyPolicyHexValueOnly.Checked ? lbHex.Tag.ToString() : lbHex.Text));

                // 复制失败
                if (result != null)
                {
                    tray.ShowBalloonTip(5000,
                                        "复制失败,请重试",
                                        result,
                                        ToolTipIcon.Error);
                }
            }
            catch (Exception e)
            {
                Util.ShowBugReportForm(e);
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: feiser2016/ColorWanted
        /// <summary>
        /// 复制HEX颜色值  双击复制RGB颜色值
        /// </summary>
        private void CopyColor(bool doubleClick)
        {
            try
            {
                ColorHistory.Record(ColorUtil.GetColor(MousePosition));
                var text = doubleClick ?
                           (trayMenuCopyPolicyRgbValueOnly.Checked ? lbRgb.Tag.ToString() : lbRgb.Text) :
                           (trayMenuCopyPolicyHexValueOnly.Checked ? lbHex.Tag.ToString() : lbHex.Text);
                var result = Util.SetClipboard(Handle, trayMenuCopyPolicyUpperCase.Checked ? text : text.ToLower());

                // 复制失败
                if (result != null)
                {
                    tray.ShowBalloonTip(5000,
                                        resources.GetString("copyFailed"),
                                        result,
                                        ToolTipIcon.Error);
                }
            }
            catch (Exception e)
            {
                Util.ShowBugReportForm(e);
            }
        }
コード例 #6
0
ファイル: Encoder.cs プロジェクト: neverbean233/apollo-studio
        public static MemoryStream EncodePreferences()
        {
            MemoryStream output = new MemoryStream();

            using (BinaryWriter writer = new BinaryWriter(output)) {
                EncodeHeader(writer);
                EncodeID(writer, typeof(Preferences));

                writer.Write(Preferences.AlwaysOnTop);
                writer.Write(Preferences.CenterTrackContents);

                writer.Write(Preferences.ChainSignalIndicators);
                writer.Write(Preferences.DeviceSignalIndicators);

                writer.Write((int)Preferences.ColorDisplayFormat);

                writer.Write((int)Preferences.LaunchpadStyle);
                writer.Write(Convert.ToInt32(Preferences.LaunchpadGridRotation));
                writer.Write((int)Preferences.LaunchpadModel);

                writer.Write(Preferences.AutoCreateKeyFilter);
                writer.Write(Preferences.AutoCreateMacroFilter);
                writer.Write(Preferences.AutoCreatePattern);

                writer.Write(Preferences.FadeSmoothnessSlider);

                writer.Write(Preferences.CopyPreviousFrame);
                writer.Write(Preferences.CaptureLaunchpad);
                writer.Write(Preferences.EnableGestures);

                writer.Write(Preferences.PaletteName);

                for (int i = 0; i < 128; i++)
                {
                    Encode(writer, Preferences.CustomPalette.BackingArray[i]);
                }

                writer.Write((int)Preferences.ImportPalette);

                writer.Write((int)Preferences.Theme);

                writer.Write(Preferences.Backup);
                writer.Write(Preferences.Autosave);

                writer.Write(Preferences.UndoLimit);

                writer.Write(Preferences.DiscordPresence);
                writer.Write(Preferences.DiscordFilename);

                int count;
                writer.Write(count = Math.Min(64, ColorHistory.Count));
                for (int i = 0; i < count; i++)
                {
                    Encode(writer, ColorHistory.GetColor(i));
                }

                writer.Write(MIDI.Devices.Count(i => i.GetType() == typeof(Launchpad)));
                for (int i = 0; i < MIDI.Devices.Count; i++)
                {
                    if (MIDI.Devices[i].GetType() == typeof(Launchpad))
                    {
                        Encode(writer, MIDI.Devices[i]);
                    }
                }

                writer.Write(Preferences.Recents.Count);
                for (int i = 0; i < Preferences.Recents.Count; i++)
                {
                    writer.Write(Preferences.Recents[i]);
                }

                writer.Write(Preferences.VirtualLaunchpads.Count);
                for (int i = 0; i < Preferences.VirtualLaunchpads.Count; i++)
                {
                    writer.Write(Preferences.VirtualLaunchpads[i]);
                }

                writer.Write(Preferences.Crashed);
                writer.Write(Preferences.CrashPath);

                writer.Write(Preferences.CheckForUpdates);

                writer.Write(Preferences.Time);
            }

            return(output);
        }
コード例 #7
0
        private void LoadSettingsFromJson()
        {
            // TODO this IO call should by Async, update GetFileWatcher helper to support async
            lock (_loadingSettingsLock)
            {
                {
                    var retry      = true;
                    var retryCount = 0;

                    while (retry)
                    {
                        try
                        {
                            retryCount++;

                            if (!_settingsUtils.SettingsExists(ColorPickerModuleName))
                            {
                                Logger.LogInfo("ColorPicker settings.json was missing, creating a new one");
                                var defaultColorPickerSettings = new ColorPickerSettings();
                                defaultColorPickerSettings.Save(_settingsUtils);
                            }

                            var settings = _settingsUtils.GetSettingsOrDefault <ColorPickerSettings>(ColorPickerModuleName);
                            if (settings != null)
                            {
                                ChangeCursor.Value              = settings.Properties.ChangeCursor;
                                ActivationShortcut.Value        = settings.Properties.ActivationShortcut.ToString();
                                CopiedColorRepresentation.Value = settings.Properties.CopiedColorRepresentation;
                                ActivationAction.Value          = settings.Properties.ActivationAction;
                                ColorHistoryLimit.Value         = settings.Properties.ColorHistoryLimit;
                                ShowColorName.Value             = settings.Properties.ShowColorName;

                                if (settings.Properties.ColorHistory == null)
                                {
                                    settings.Properties.ColorHistory = new System.Collections.Generic.List <string>();
                                }

                                _loadingColorsHistory = true;
                                ColorHistory.Clear();
                                foreach (var item in settings.Properties.ColorHistory)
                                {
                                    ColorHistory.Add(item);
                                }

                                _loadingColorsHistory = false;

                                VisibleColorFormats.Clear();
                                foreach (var item in settings.Properties.VisibleColorFormats)
                                {
                                    if (item.Value)
                                    {
                                        VisibleColorFormats.Add(item.Key);
                                    }
                                }
                            }

                            retry = false;
                        }
                        catch (IOException ex)
                        {
                            if (retryCount > MaxNumberOfRetry)
                            {
                                retry = false;
                            }

                            Logger.LogError("Failed to read changed settings", ex);
                            Thread.Sleep(500);
                        }
                        catch (Exception ex)
                        {
                            if (retryCount > MaxNumberOfRetry)
                            {
                                retry = false;
                            }

                            Logger.LogError("Failed to read changed settings", ex);
                            Thread.Sleep(500);
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: vincent-deng/ColorWanted
        private void ShowColorPicker()
        {
            if (trayMenuShowColorPicker.Checked)
            {
                return;
            }

            if (colorPicker == null)
            {
                colorPicker = new ColorDialog
                {
                    FullOpen = true
                };
            }
            try
            {
                // 显示时,尝试从剪贴板中加载已经复制的颜色
                if (Clipboard.ContainsText(TextDataFormat.Text))
                {
                    var color = Color.Empty;
                    var c     = Clipboard.GetText().Trim();
                    if (c.Length == 7 && c[0] == '#')
                    {
                        // hex
                        var r = Convert.ToInt16(c.Substring(1, 2), 16);
                        var g = Convert.ToInt16(c.Substring(3, 2), 16);
                        var b = Convert.ToInt16(c.Substring(5, 2), 16);

                        color = Color.FromArgb(r, g, b);
                    }
                    else if (c.StartsWith("rgb", StringComparison.OrdinalIgnoreCase))
                    {
                        // rgb
                        var temp = c.Substring(3).Trim('(', ')').Split(',');
                        if (temp.Length == 3)
                        {
                            var colors = temp.Select(int.Parse).ToArray();
                            color = Color.FromArgb(colors[0], colors[1], colors[2]);
                        }
                    }

                    if (!color.IsEmpty)
                    {
                        colorPicker.Color = color;
                    }
                }
            }
            catch
            {
                // ignore
            }

            // 加载保存的自定义颜色
            colorPicker.CustomColors = Settings.Base.CustomColors;

            trayMenuShowColorPicker.Checked = true;
            if (DialogResult.OK == colorPicker.ShowDialog(this))
            {
                var cl = colorPicker.Color;
                ColorHistory.Record(cl);
                Util.SetClipboard(Handle, string.Format("#{0:X2}{1:X2}{2:X2}", cl.R, cl.G, cl.B));

                // 保存自定义颜色
                Settings.Base.CustomColors = colorPicker.CustomColors;
            }

            trayMenuShowColorPicker.Checked = false;
        }
コード例 #9
0
        static dynamic Decode(BinaryReader reader, int version, Type ensure = null, bool root = false)
        {
            Type t = DecodeID(reader);

            if (ensure != null && ensure != t)
            {
                throw new InvalidDataException();
            }

            if (t == typeof(Preferences) && root)
            {
                Preferences.AlwaysOnTop         = reader.ReadBoolean();
                Preferences.CenterTrackContents = reader.ReadBoolean();

                if (version >= 9)
                {
                    Preferences.LaunchpadStyle = (LaunchpadStyles)reader.ReadInt32();
                }

                if (version >= 14)
                {
                    Preferences.LaunchpadGridRotation = reader.ReadInt32() > 0;
                }

                Preferences.AutoCreateKeyFilter  = reader.ReadBoolean();
                Preferences.AutoCreatePageFilter = reader.ReadBoolean();

                if (version >= 11)
                {
                    Preferences.AutoCreatePattern = reader.ReadBoolean();
                }

                Preferences.FadeSmoothness    = reader.ReadDouble();
                Preferences.CopyPreviousFrame = reader.ReadBoolean();

                if (version >= 7)
                {
                    Preferences.CaptureLaunchpad = reader.ReadBoolean();
                }

                Preferences.EnableGestures = reader.ReadBoolean();

                if (version >= 7)
                {
                    Preferences.PaletteName   = reader.ReadString();
                    Preferences.CustomPalette = new Palette((from i in Enumerable.Range(0, 128) select(Color) Decode(reader, version)).ToArray());
                    Preferences.ImportPalette = (Palettes)reader.ReadInt32();

                    Preferences.Theme = (Themes)reader.ReadInt32();
                }

                if (version >= 10)
                {
                    Preferences.Backup   = reader.ReadBoolean();
                    Preferences.Autosave = reader.ReadBoolean();
                }

                if (version >= 12)
                {
                    Preferences.UndoLimit = reader.ReadBoolean();
                }

                if (version <= 0)
                {
                    Preferences.DiscordPresence = true;
                    reader.ReadBoolean();
                }
                else
                {
                    Preferences.DiscordPresence = reader.ReadBoolean();
                }

                Preferences.DiscordFilename = reader.ReadBoolean();

                ColorHistory.Set(
                    (from i in Enumerable.Range(0, reader.ReadInt32()) select(Color) Decode(reader, version)).ToList()
                    );

                if (version >= 2)
                {
                    MIDI.Devices = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Launchpad) Decode(reader, version)).ToList();
                }

                if (version >= 15)
                {
                    Preferences.Recents   = (from i in Enumerable.Range(0, reader.ReadInt32()) select reader.ReadString()).ToList();
                    Preferences.CrashName = reader.ReadString();
                    Preferences.CrashPath = reader.ReadString();
                }

                if (version >= 16)
                {
                    Preferences.CheckForUpdates = reader.ReadBoolean();
                }

                if (version >= 17)
                {
                    Preferences.BaseTime = reader.ReadInt64();
                }

                return(null);
            }
            else if (t == typeof(Copyable))
            {
                return(new Copyable()
                {
                    Contents = (from i in Enumerable.Range(0, reader.ReadInt32()) select(ISelect) Decode(reader, version)).ToList()
                });
            }
            else if (t == typeof(Project))
            {
                int          bpm    = reader.ReadInt32();
                int          page   = reader.ReadInt32();
                List <Track> tracks = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Track) Decode(reader, version)).ToList();

                string author  = "";
                long   time    = 0;
                long   started = 0;

                if (version >= 17)
                {
                    author  = reader.ReadString();
                    time    = reader.ReadInt64();
                    started = reader.ReadInt64();
                }

                return(new Project(bpm, page, tracks, author, time, started));
            }
            else if (t == typeof(Track))
            {
                Chain     chain = (Chain)Decode(reader, version);
                Launchpad lp    = (Launchpad)Decode(reader, version);
                string    name  = reader.ReadString();

                bool enabled = true;
                if (version >= 8)
                {
                    enabled = reader.ReadBoolean();
                }

                return(new Track(chain, lp, name)
                {
                    Enabled = enabled
                });
            }
            else if (t == typeof(Chain))
            {
                List <Device> devices = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Device) Decode(reader, version)).ToList();
                string        name    = reader.ReadString();

                bool enabled = true;
                if (version >= 6)
                {
                    enabled = reader.ReadBoolean();
                }

                return(new Chain(devices, name)
                {
                    Enabled = enabled
                });
            }
            else if (t == typeof(Device))
            {
                bool collapsed = false;
                if (version >= 5)
                {
                    collapsed = reader.ReadBoolean();
                }

                bool enabled = true;
                if (version >= 5)
                {
                    enabled = reader.ReadBoolean();
                }

                Device ret = (Device)Decode(reader, version);
                ret.Collapsed = collapsed;
                ret.Enabled   = enabled;

                return(ret);
            }
            else if (t == typeof(Launchpad))
            {
                string name = reader.ReadString();
                if (name == "")
                {
                    return(MIDI.NoOutput);
                }

                InputType format = InputType.DrumRack;
                if (version >= 2)
                {
                    format = (InputType)reader.ReadInt32();
                }

                RotationType rotation = RotationType.D0;
                if (version >= 9)
                {
                    rotation = (RotationType)reader.ReadInt32();
                }

                foreach (Launchpad lp in MIDI.Devices)
                {
                    if (lp.Name == name)
                    {
                        if (lp.GetType() == typeof(Launchpad))
                        {
                            lp.InputFormat = format;
                            lp.Rotation    = rotation;
                        }
                        return(lp);
                    }
                }

                Launchpad ret;
                if (name.Contains("Virtual Launchpad "))
                {
                    ret = new VirtualLaunchpad(name);
                }
                else if (name.Contains("Ableton Connector "))
                {
                    ret = new AbletonLaunchpad(name);
                }
                else
                {
                    ret = new Launchpad(name, format, rotation);
                }

                MIDI.Devices.Add(ret);

                return(ret);
            }
            else if (t == typeof(Group))
            {
                return(new Group(
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Chain) Decode(reader, version)).ToList(),
                           reader.ReadBoolean()? (int?)reader.ReadInt32() : null
                           ));
            }

            else if (t == typeof(Choke))
            {
                return(new Choke(
                           reader.ReadInt32(),
                           (Chain)Decode(reader, version)
                           ));
            }

            else if (t == typeof(Clear))
            {
                return(new Clear(
                           (ClearType)reader.ReadInt32()
                           ));
            }

            else if (t == typeof(ColorFilter))
            {
                return(new ColorFilter(
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble()
                           ));
            }

            else if (t == typeof(Copy))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                double gate;
                if (version <= 13)
                {
                    gate = (double)reader.ReadDecimal();
                }
                else
                {
                    gate = reader.ReadDouble();
                }

                return(new Copy(
                           time,
                           gate,
                           (CopyType)reader.ReadInt32(),
                           (GridType)reader.ReadInt32(),
                           reader.ReadBoolean(),
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Offset) Decode(reader, version)).ToList()
                           ));
            }
            else if (t == typeof(Delay))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                double gate;
                if (version <= 13)
                {
                    gate = (double)reader.ReadDecimal();
                }
                else
                {
                    gate = reader.ReadDouble();
                }

                return(new Delay(time, gate));
            }
            else if (t == typeof(Fade))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                double gate;
                if (version <= 13)
                {
                    gate = (double)reader.ReadDecimal();
                }
                else
                {
                    gate = reader.ReadDouble();
                }

                FadePlaybackType playmode = (FadePlaybackType)reader.ReadInt32();

                int           count;
                List <Color>  colors    = (from i in Enumerable.Range(0, count = reader.ReadInt32()) select(Color) Decode(reader, version)).ToList();
                List <double> positions = (from i in Enumerable.Range(0, count) select(version <= 13)? (double)reader.ReadDecimal() : reader.ReadDouble()).ToList();

                return(new Fade(time, gate, playmode, colors, positions));
            }
            else if (t == typeof(Flip))
            {
                return(new Flip(
                           (FlipType)reader.ReadInt32(),
                           reader.ReadBoolean()
                           ));
            }

            else if (t == typeof(Hold))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                double gate;
                if (version <= 13)
                {
                    gate = (double)reader.ReadDecimal();
                }
                else
                {
                    gate = reader.ReadDouble();
                }

                return(new Hold(
                           time,
                           gate,
                           reader.ReadBoolean(),
                           reader.ReadBoolean()
                           ));
            }
            else if (t == typeof(KeyFilter))
            {
                bool[] filter;
                if (version <= 18)
                {
                    List <bool> oldFilter = (from i in Enumerable.Range(0, 100) select reader.ReadBoolean()).ToList();
                    oldFilter.Insert(99, false);
                    filter = oldFilter.ToArray();
                }
                else
                {
                    filter = (from i in Enumerable.Range(0, 101) select reader.ReadBoolean()).ToArray();
                }

                return(new KeyFilter(filter));
            }
            else if (t == typeof(Layer))
            {
                int target = reader.ReadInt32();

                BlendingType blending = BlendingType.Normal;
                if (version >= 5)
                {
                    if (version == 5)
                    {
                        blending = (BlendingType)reader.ReadInt32();
                        if ((int)blending == 2)
                        {
                            blending = BlendingType.Mask;
                        }
                    }
                    else
                    {
                        blending = (BlendingType)reader.ReadInt32();
                    }
                }

                int range = 200;
                if (version >= 21)
                {
                    range = reader.ReadInt32();
                }

                return(new Layer(target, blending, range));
            }
            else if (t == typeof(Move))
            {
                return(new Move(
                           Decode(reader, version),
                           (GridType)reader.ReadInt32(),
                           reader.ReadBoolean()
                           ));
            }

            else if (t == typeof(Multi))
            {
                return(new Multi(
                           Decode(reader, version),
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Chain) Decode(reader, version)).ToList(),
                           reader.ReadBoolean()? (int?)reader.ReadInt32() : null,
                           (MultiType)reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Output))
            {
                return(new Output(
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(PageFilter))
            {
                return(new PageFilter(
                           (from i in Enumerable.Range(0, 100) select reader.ReadBoolean()).ToArray()
                           ));
            }

            else if (t == typeof(Paint))
            {
                return(new Paint(
                           Decode(reader, version)
                           ));
            }

            else if (t == typeof(Pattern))
            {
                int repeats = 1;
                if (version >= 11)
                {
                    repeats = reader.ReadInt32();
                }

                double gate;
                if (version <= 13)
                {
                    gate = (double)reader.ReadDecimal();
                }
                else
                {
                    gate = reader.ReadDouble();
                }

                List <Frame> frames = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Frame) Decode(reader, version)).ToList();
                PlaybackType mode   = (PlaybackType)reader.ReadInt32();

                bool chokeenabled = false;
                int  choke        = 8;

                if (version <= 10)
                {
                    chokeenabled = reader.ReadBoolean();

                    if (version <= 0)
                    {
                        if (chokeenabled)
                        {
                            choke = reader.ReadInt32();
                        }
                    }
                    else
                    {
                        choke = reader.ReadInt32();
                    }
                }

                bool infinite = false;
                if (version >= 4)
                {
                    infinite = reader.ReadBoolean();
                }

                int?rootkey = null;
                if (version >= 12)
                {
                    rootkey = reader.ReadBoolean()? (int?)reader.ReadInt32() : null;
                }

                bool wrap = false;
                if (version >= 13)
                {
                    wrap = reader.ReadBoolean();
                }

                int expanded = reader.ReadInt32();

                Pattern ret = new Pattern(repeats, gate, frames, mode, infinite, rootkey, wrap, expanded);

                if (chokeenabled)
                {
                    return(new Choke(choke, new Chain(new List <Device>()
                    {
                        ret
                    })));
                }

                return(ret);
            }
            else if (t == typeof(Preview))
            {
                return(new Preview());
            }

            else if (t == typeof(Rotate))
            {
                return(new Rotate(
                           (RotateType)reader.ReadInt32(),
                           reader.ReadBoolean()
                           ));
            }

            else if (t == typeof(Switch))
            {
                int page = reader.ReadInt32();

                if (18 <= version && version <= 21 && reader.ReadBoolean())
                {
                    return(new Group(new List <Chain>()
                    {
                        new Chain(new List <Device>()
                        {
                            new Switch(page), new Clear(ClearType.Multi)
                        }, "Switch Reset")
                    }));
                }

                return(new Switch(page));
            }
            else if (t == typeof(Tone))
            {
                return(new Tone(
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble()
                           ));
            }

            else if (t == typeof(Color))
            {
                return(new Color(
                           reader.ReadByte(),
                           reader.ReadByte(),
                           reader.ReadByte()
                           ));
            }

            else if (t == typeof(Frame))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                Color[] screen;
                if (version <= 19)
                {
                    List <Color> oldScreen = (from i in Enumerable.Range(0, 100) select(Color) Decode(reader, version)).ToList();
                    oldScreen.Insert(99, new Color(0));
                    screen = oldScreen.ToArray();
                }
                else
                {
                    screen = (from i in Enumerable.Range(0, 101) select(Color) Decode(reader, version)).ToArray();
                }

                return(new Frame(time, screen));
            }
            else if (t == typeof(Length))
            {
                return(new Length(
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Offset))
            {
                return(new Offset(
                           reader.ReadInt32(),
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Time))
            {
                return(new Time(
                           reader.ReadBoolean(),
                           Decode(reader, version),
                           reader.ReadInt32()
                           ));
            }

            throw new InvalidDataException();
        }
コード例 #10
0
 void ClearColorHistory(object sender, RoutedEventArgs e) => ColorHistory.Clear();
コード例 #11
0
 public void AddColorToHistory(ColorEntry entry)
 {
     ColorHistory.Add(entry);
 }
コード例 #12
0
ファイル: Decoder.cs プロジェクト: Gardinex/apollo-studio
        private static dynamic Decode(BinaryReader reader, int version, Type ensure = null, bool root = false)
        {
            Type t = DecodeID(reader);

            if (ensure != null && ensure != t)
            {
                return(new InvalidDataException());
            }

            if (t == typeof(Preferences) && root)
            {
                try {
                    Preferences.AlwaysOnTop         = reader.ReadBoolean();
                    Preferences.CenterTrackContents = reader.ReadBoolean();

                    if (version >= 9)
                    {
                        Preferences.LaunchpadStyle = (Preferences.LaunchpadStyles)reader.ReadInt32();
                    }

                    Preferences.AutoCreateKeyFilter  = reader.ReadBoolean();
                    Preferences.AutoCreatePageFilter = reader.ReadBoolean();

                    if (version >= 11)
                    {
                        Preferences.AutoCreatePattern = reader.ReadBoolean();
                    }

                    Preferences.FadeSmoothness    = reader.ReadDouble();
                    Preferences.CopyPreviousFrame = reader.ReadBoolean();

                    if (version >= 7)
                    {
                        Preferences.CaptureLaunchpad = reader.ReadBoolean();
                    }

                    Preferences.EnableGestures = reader.ReadBoolean();

                    if (version >= 7)
                    {
                        Preferences.PaletteName   = reader.ReadString();
                        Preferences.CustomPalette = new Palette((from i in Enumerable.Range(0, 128) select(Color) Decode(reader, version)).ToArray());
                        Preferences.ImportPalette = (Preferences.Palettes)reader.ReadInt32();

                        Preferences.Theme = (Preferences.Themes)reader.ReadInt32();
                    }

                    if (version >= 10)
                    {
                        Preferences.Backup   = reader.ReadBoolean();
                        Preferences.Autosave = reader.ReadBoolean();
                    }

                    if (version >= 12)
                    {
                        Preferences.UndoLimit = reader.ReadBoolean();
                    }

                    if (version <= 0)
                    {
                        Preferences.DiscordPresence = true;
                        reader.ReadBoolean();
                    }
                    else
                    {
                        Preferences.DiscordPresence = reader.ReadBoolean();
                    }

                    Preferences.DiscordFilename = reader.ReadBoolean();

                    ColorHistory.Set(
                        (from i in Enumerable.Range(0, reader.ReadInt32()) select(Color) Decode(reader, version)).ToList()
                        );

                    if (version >= 2)
                    {
                        MIDI.Devices = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Launchpad) Decode(reader, version)).ToList();
                    }

                    return(null);
                } catch {
                    Program.Log("Error reading Preferences");
                    return(null);
                }
            }
            else if (t == typeof(Copyable))
            {
                return(new Copyable()
                {
                    Contents = (from i in Enumerable.Range(0, reader.ReadInt32()) select(ISelect) Decode(reader, version)).ToList()
                });
            }
            else if (t == typeof(Project))
            {
                return(new Project(
                           reader.ReadInt32(),
                           reader.ReadInt32(),
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Track) Decode(reader, version)).ToList()
                           ));
            }

            else if (t == typeof(Track))
            {
                Chain     chain = (Chain)Decode(reader, version);
                Launchpad lp    = (Launchpad)Decode(reader, version);
                string    name  = reader.ReadString();

                bool enabled = true;
                if (version >= 8)
                {
                    enabled = reader.ReadBoolean();
                }

                return(new Track(chain, lp, name)
                {
                    Enabled = enabled
                });
            }
            else if (t == typeof(Chain))
            {
                List <Device> devices = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Device) Decode(reader, version)).ToList();
                string        name    = reader.ReadString();

                bool enabled = true;
                if (version >= 6)
                {
                    enabled = reader.ReadBoolean();
                }

                return(new Chain(devices, name)
                {
                    Enabled = enabled
                });
            }
            else if (t == typeof(Device))
            {
                bool collapsed = false;
                if (version >= 5)
                {
                    collapsed = reader.ReadBoolean();
                }

                bool enabled = true;
                if (version >= 5)
                {
                    enabled = reader.ReadBoolean();
                }

                Device ret = (Device)Decode(reader, version);
                ret.Collapsed = collapsed;
                ret.Enabled   = enabled;

                return(ret);
            }
            else if (t == typeof(Launchpad))
            {
                string name = reader.ReadString();
                if (name == "")
                {
                    return(MIDI.NoOutput);
                }

                Launchpad.InputType format = Launchpad.InputType.DrumRack;
                if (version >= 2)
                {
                    format = (Launchpad.InputType)reader.ReadInt32();
                }

                Launchpad.RotationType rotation = Launchpad.RotationType.D0;
                if (version >= 9)
                {
                    rotation = (Launchpad.RotationType)reader.ReadInt32();
                }

                foreach (Launchpad lp in MIDI.Devices)
                {
                    if (lp.Name == name)
                    {
                        lp.InputFormat = format;
                        lp.Rotation    = rotation;
                        return(lp);
                    }
                }

                return(new Launchpad(name, format, rotation));
            }
            else if (t == typeof(Group))
            {
                return(new Group(
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Chain) Decode(reader, version)).ToList(),
                           reader.ReadBoolean()? (int?)reader.ReadInt32() : null
                           ));
            }

            else if (t == typeof(Choke))
            {
                return(new Choke(
                           reader.ReadInt32(),
                           (Chain)Decode(reader, version)
                           ));
            }

            else if (t == typeof(Copy))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                return(new Copy(
                           time,
                           reader.ReadDecimal(),
                           (Copy.CopyType)reader.ReadInt32(),
                           (Copy.GridType)reader.ReadInt32(),
                           reader.ReadBoolean(),
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Offset) Decode(reader, version)).ToList()
                           ));
            }
            else if (t == typeof(Delay))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                return(new Delay(
                           time,
                           reader.ReadDecimal()
                           ));
            }
            else if (t == typeof(Fade))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                int count;
                return(new Fade(
                           time,
                           reader.ReadDecimal(),
                           (Fade.PlaybackType)reader.ReadInt32(),
                           (from i in Enumerable.Range(0, count = reader.ReadInt32()) select(Color) Decode(reader, version)).ToList(),
                           (from i in Enumerable.Range(0, count) select reader.ReadDecimal()).ToList()
                           ));
            }
            else if (t == typeof(Flip))
            {
                return(new Flip(
                           (Flip.FlipType)reader.ReadInt32(),
                           reader.ReadBoolean()
                           ));
            }

            else if (t == typeof(Hold))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                return(new Hold(
                           time,
                           reader.ReadDecimal(),
                           reader.ReadBoolean(),
                           reader.ReadBoolean()
                           ));
            }
            else if (t == typeof(KeyFilter))
            {
                return(new KeyFilter(
                           (from i in Enumerable.Range(0, 100) select reader.ReadBoolean()).ToArray()
                           ));
            }

            else if (t == typeof(Layer))
            {
                int target = reader.ReadInt32();

                Signal.BlendingType blending = Signal.BlendingType.Normal;
                if (version >= 5)
                {
                    if (version == 5)
                    {
                        blending = (Signal.BlendingType)reader.ReadInt32();
                        if ((int)blending == 2)
                        {
                            blending = Signal.BlendingType.Mask;
                        }
                    }
                    else
                    {
                        blending = (Signal.BlendingType)reader.ReadInt32();
                    }
                }

                return(new Layer(
                           target,
                           blending
                           ));
            }
            else if (t == typeof(Move))
            {
                return(new Move(
                           Decode(reader, version),
                           (Move.GridType)reader.ReadInt32(),
                           reader.ReadBoolean()
                           ));
            }

            else if (t == typeof(Multi))
            {
                return(new Multi(
                           Decode(reader, version),
                           (from i in Enumerable.Range(0, reader.ReadInt32()) select(Chain) Decode(reader, version)).ToList(),
                           reader.ReadBoolean()? (int?)reader.ReadInt32() : null,
                           (Multi.MultiType)reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Output))
            {
                return(new Output(
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(PageFilter))
            {
                return(new PageFilter(
                           (from i in Enumerable.Range(0, 100) select reader.ReadBoolean()).ToArray()
                           ));
            }

            else if (t == typeof(Switch))
            {
                return(new Switch(
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Paint))
            {
                return(new Paint(
                           Decode(reader, version)
                           ));
            }

            else if (t == typeof(Pattern))
            {
                int repeats = 1;
                if (version >= 11)
                {
                    repeats = reader.ReadInt32();
                }

                decimal              gate   = reader.ReadDecimal();
                List <Frame>         frames = (from i in Enumerable.Range(0, reader.ReadInt32()) select(Frame) Decode(reader, version)).ToList();
                Pattern.PlaybackType mode   = (Pattern.PlaybackType)reader.ReadInt32();

                bool chokeenabled = false;
                int  choke        = 8;

                if (version <= 10)
                {
                    chokeenabled = reader.ReadBoolean();

                    if (version <= 0)
                    {
                        if (chokeenabled)
                        {
                            choke = reader.ReadInt32();
                        }
                    }
                    else
                    {
                        choke = reader.ReadInt32();
                    }
                }

                bool infinite = false;
                if (version >= 4)
                {
                    infinite = reader.ReadBoolean();
                }

                int?rootkey = null;
                if (version >= 12)
                {
                    rootkey = reader.ReadBoolean()? (int?)reader.ReadInt32() : null;
                }

                bool wrap = false;
                if (version >= 12)
                {
                    wrap = reader.ReadBoolean();
                }

                int expanded = reader.ReadInt32();

                Pattern ret = new Pattern(repeats, gate, frames, mode, infinite, rootkey, wrap, expanded);

                if (chokeenabled)
                {
                    return(new Choke(choke, new Chain(new List <Device>()
                    {
                        ret
                    })));
                }

                return(ret);
            }
            else if (t == typeof(Preview))
            {
                return(new Preview());
            }

            else if (t == typeof(Rotate))
            {
                return(new Rotate(
                           (Rotate.RotateType)reader.ReadInt32(),
                           reader.ReadBoolean()
                           ));
            }

            else if (t == typeof(Tone))
            {
                return(new Tone(
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble(),
                           reader.ReadDouble()
                           ));
            }

            else if (t == typeof(Color))
            {
                return(new Color(
                           reader.ReadByte(),
                           reader.ReadByte(),
                           reader.ReadByte()
                           ));
            }

            else if (t == typeof(Frame))
            {
                Time time;
                if (version <= 2)
                {
                    time = new Time(
                        reader.ReadBoolean(),
                        Decode(reader, version),
                        reader.ReadInt32()
                        );
                }
                else
                {
                    time = Decode(reader, version);
                }

                return(new Frame(
                           time,
                           (from i in Enumerable.Range(0, 100) select(Color) Decode(reader, version)).ToArray()
                           ));
            }
            else if (t == typeof(Length))
            {
                return(new Length(
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Offset))
            {
                return(new Offset(
                           reader.ReadInt32(),
                           reader.ReadInt32()
                           ));
            }

            else if (t == typeof(Time))
            {
                return(new Time(
                           reader.ReadBoolean(),
                           Decode(reader, version),
                           reader.ReadInt32()
                           ));
            }

            return(new InvalidDataException());
        }
コード例 #13
0
ファイル: Encoder.cs プロジェクト: vaaski/apollo-studio
        public static byte[] EncodeConfig() => Encode(writer => {
            EncodeID(writer, typeof(Preferences));

            writer.Write(Preferences.AlwaysOnTop);
            writer.Write(Preferences.CenterTrackContents);

            writer.Write(Preferences.ChainSignalIndicators);
            writer.Write(Preferences.DeviceSignalIndicators);

            writer.Write((int)Preferences.ColorDisplayFormat);

            writer.Write((int)Preferences.LaunchpadStyle);
            writer.Write(Convert.ToInt32(Preferences.LaunchpadGridRotation));
            writer.Write((int)Preferences.LaunchpadModel);

            writer.Write(Preferences.AutoCreateKeyFilter);
            writer.Write(Preferences.AutoCreateMacroFilter);
            writer.Write(Preferences.AutoCreatePattern);

            writer.Write(Preferences.FPSLimit);

            writer.Write(Preferences.CopyPreviousFrame);
            writer.Write(Preferences.CaptureLaunchpad);
            writer.Write(Preferences.EnableGestures);
            writer.Write(Preferences.RememberPatternPosition);

            writer.Write(Preferences.PaletteName);

            for (int i = 0; i < 128; i++)
            {
                Encode(writer, Preferences.CustomPalette.BackingArray[i]);
            }

            writer.Write((int)Preferences.ImportPalette);

            writer.Write((int)Preferences.Theme);

            writer.Write(Preferences.Backup);
            writer.Write(Preferences.Autosave);

            writer.Write(Preferences.UndoLimit);

            writer.Write(Preferences.DiscordPresence);
            writer.Write(Preferences.DiscordFilename);

            int count;
            writer.Write(count = Math.Min(64, ColorHistory.Count));
            for (int i = 0; i < count; i++)
            {
                Encode(writer, ColorHistory.GetColor(i));
            }

            writer.Write(MIDI.Devices.Count(i => i.GetType() == typeof(Launchpad)));
            for (int i = 0; i < MIDI.Devices.Count; i++)
            {
                if (MIDI.Devices[i].GetType() == typeof(Launchpad))
                {
                    Encode(writer, MIDI.Devices[i]);
                }
            }

            writer.Write(Preferences.Recents.Count);
            for (int i = 0; i < Preferences.Recents.Count; i++)
            {
                writer.Write(Preferences.Recents[i]);
            }

            writer.Write(Preferences.VirtualLaunchpads.Count);
            for (int i = 0; i < Preferences.VirtualLaunchpads.Count; i++)
            {
                writer.Write(Preferences.VirtualLaunchpads[i]);
            }

            writer.Write(Preferences.Crashed);
            writer.Write(Preferences.CrashPath);

            writer.Write(Preferences.CheckForUpdates);
        });
コード例 #14
0
ファイル: Decoder.cs プロジェクト: vaaski/apollo-studio
        public static void DecodeConfig(Stream input) => Decode(input, (reader, version) => {
            Preferences.AlwaysOnTop         = reader.ReadBoolean();
            Preferences.CenterTrackContents = reader.ReadBoolean();

            if (version >= 24)
            {
                Preferences.ChainSignalIndicators  = reader.ReadBoolean();
                Preferences.DeviceSignalIndicators = reader.ReadBoolean();
            }
            else if (version >= 23)
            {
                Preferences.ChainSignalIndicators = Preferences.DeviceSignalIndicators = reader.ReadBoolean();
            }

            if (version >= 28)
            {
                Preferences.ColorDisplayFormat = (ColorDisplayType)reader.ReadInt32();
            }

            if (version >= 9)
            {
                Preferences.LaunchpadStyle = (LaunchpadStyles)reader.ReadInt32();
            }

            if (version >= 14)
            {
                Preferences.LaunchpadGridRotation = reader.ReadInt32() > 0;
            }

            if (version >= 24)
            {
                LaunchpadModels model = (LaunchpadModels)reader.ReadInt32();

                if (version <= 28 && model >= LaunchpadModels.ProMK3)
                {
                    model++;
                }

                Preferences.LaunchpadModel = model;
            }

            Preferences.AutoCreateKeyFilter   = reader.ReadBoolean();
            Preferences.AutoCreateMacroFilter = reader.ReadBoolean();

            if (version >= 11)
            {
                Preferences.AutoCreatePattern = reader.ReadBoolean();
            }

            if (version >= 31)
            {
                Preferences.FPSLimit = reader.ReadInt32();
            }
            else
            {
                Preferences.FPSLimit = Math.Max(180, (int)(1081.45 * Math.Pow(Math.Log(1 - reader.ReadDouble()), 2) + 2));
            }

            Preferences.CopyPreviousFrame = reader.ReadBoolean();

            if (version >= 7)
            {
                Preferences.CaptureLaunchpad = reader.ReadBoolean();
            }

            Preferences.EnableGestures = reader.ReadBoolean();

            if (version >= 32)
            {
                Preferences.RememberPatternPosition = reader.ReadBoolean();
            }

            if (version >= 7)
            {
                Preferences.PaletteName   = reader.ReadString();
                Preferences.CustomPalette = new Palette(Enumerable.Range(0, 128).Select(i => Decode <Color>(reader, version)).ToArray());
                Preferences.ImportPalette = (Palettes)reader.ReadInt32();

                Preferences.Theme = (ThemeType)reader.ReadInt32();
            }

            if (version >= 10)
            {
                Preferences.Backup   = reader.ReadBoolean();
                Preferences.Autosave = reader.ReadBoolean();
            }

            if (version >= 12)
            {
                Preferences.UndoLimit = reader.ReadBoolean();
            }

            if (version <= 0)
            {
                Preferences.DiscordPresence = true;
                reader.ReadBoolean();
            }
            else
            {
                Preferences.DiscordPresence = reader.ReadBoolean();
            }

            Preferences.DiscordFilename = reader.ReadBoolean();

            ColorHistory.Set(
                Enumerable.Range(0, reader.ReadInt32()).Select(i => Decode <Color>(reader, version)).ToList()
                );

            if (version >= 2)
            {
                MIDI.Devices = Enumerable.Range(0, reader.ReadInt32()).Select(i => Decode <Launchpad>(reader, version)).ToList();
            }

            if (version >= 15)
            {
                Preferences.Recents = Enumerable.Range(0, reader.ReadInt32()).Select(i => reader.ReadString()).ToList();
            }

            if (version >= 25)
            {
                Preferences.VirtualLaunchpads = Enumerable.Range(0, reader.ReadInt32()).Select(i => reader.ReadInt32()).ToList();
            }

            if (15 <= version && version <= 22)
            {
                reader.ReadString();
                reader.ReadString();
            }

            if (version >= 23)
            {
                Preferences.Crashed   = reader.ReadBoolean();
                Preferences.CrashPath = reader.ReadString();
            }

            if (version >= 16)
            {
                Preferences.CheckForUpdates = reader.ReadBoolean();
            }

            if (17 <= version && version <= 28)
            {
                Preferences.BaseTime = reader.ReadInt64();
            }
        });