Example #1
0
        public Project ShowDialog(FamiStudioForm parent)
        {
            var project = (Project)null;

            if (dialog != null)
            {
                // This is only ran in desktop and this isnt really async, so its ok.
                dialog.ShowDialogAsync(parent, (r) =>
                {
                    if (r == DialogResult.OK)
                    {
                        var songIndex           = Array.IndexOf(songNames, dialog.Properties.GetPropertyValue <string>(0));;
                        var duration            = dialog.Properties.GetPropertyValue <int>(1);
                        var patternLen          = dialog.Properties.GetPropertyValue <int>(2);
                        var startFrame          = dialog.Properties.GetPropertyValue <int>(3);
                        var removeIntro         = dialog.Properties.GetPropertyValue <bool>(4);
                        var reverseDpcmBits     = dialog.Properties.GetPropertyValue <bool>(5);
                        var preserveDpcmPadding = dialog.Properties.GetPropertyValue <bool>(6);

                        project = new NsfFile().Load(filename, songIndex, duration, patternLen, startFrame, removeIntro, reverseDpcmBits, preserveDpcmPadding);
                    }
                });
            }

            return(project);
        }
Example #2
0
        private void QwertyPage_PropertyClicked(PropertyPage props, ClickType click, int propIdx, int rowIdx, int colIdx)
        {
            if (propIdx == 1 && colIdx >= 2)
            {
                if (click == ClickType.Double)
                {
                    var dlg = new PropertyDialog("", 300, false, true, dialog);
                    dlg.Properties.AddLabel(null, "Press the new key or ESC to cancel.");
                    dlg.Properties.Build();

                    // TODO : Make this cross-platform.
#if FAMISTUDIO_WINDOWS
                    dlg.KeyDown += (sender, e) =>
                    {
                        if (PlatformUtils.KeyCodeToString((int)e.KeyCode) != null)
                        {
                            if (e.KeyCode != Keys.Escape)
                            {
                                AssignQwertyKey(rowIdx, colIdx - 2, (int)e.KeyCode);
                            }
                            dlg.Close();
                        }
                    };
#elif FAMISTUDIO_LINUX || FAMISTUDIO_MACOS
                    dlg.KeyPressEvent += (o, args) =>
                    {
                        // These 2 keys are used by the QWERTY input.
                        if (args.Event.Key != Gdk.Key.Tab &&
                            args.Event.Key != Gdk.Key.BackSpace &&
                            PlatformUtils.KeyCodeToString((int)args.Event.Key) != null)
                        {
                            if (args.Event.Key != Gdk.Key.Escape)
                            {
                                AssignQwertyKey(rowIdx, colIdx - 2, (int)args.Event.Key);
                            }
                            dlg.Accept();
                        }
                    };
#endif
                    dlg.ShowDialogAsync(null, (r) => { });

                    pages[(int)ConfigSection.QWERTY].UpdateMultiColumnList(1, GetQwertyMappingStrings());
                }
                else if (click == ClickType.Right)
                {
                    qwertyKeys[rowIdx, colIdx - 2] = -1;
                    pages[(int)ConfigSection.QWERTY].UpdateMultiColumnList(1, GetQwertyMappingStrings());
                }
            }
            else if (propIdx == 2 && click == ClickType.Button)
            {
                Array.Copy(Settings.DefaultQwertyKeys, qwertyKeys, Settings.DefaultQwertyKeys.Length);
                pages[(int)ConfigSection.QWERTY].UpdateMultiColumnList(1, GetQwertyMappingStrings());
            }
        }
Example #3
0
        public void ReportProgress(float progress)
        {
            MainThread.InvokeOnMainThreadAsync(() =>
            {
                if (!shown)
                {
                    shown = true;
                    dialog.ShowDialogAsync(parentForm, (r) => { abort = r != DialogResult.None; });
                }

                dialog.Properties.SetPropertyValue(0, progress);
            });
        }
Example #4
0
        private void Properties_PropertyClicked(PropertyPage props, ClickType click, int propIdx, int rowIdx, int colIdx)
        {
            if (click == ClickType.Button && colIdx == 2)
            {
                var src = channelSources[rowIdx];

                if (src.type == MidiSourceType.Channel && src.index == 9)
                {
                    var dlg = new PropertyDialog("MIDI Source", 300, true, true, dialog);
                    dlg.Properties.AddLabel(null, "Channel 10 keys:");                                                    // 0
                    dlg.Properties.AddCheckBoxList(null, MidiFileReader.MidiDrumKeyNames, GetSelectedChannel10Keys(src)); // 1
                    dlg.Properties.AddButton(null, "Select All");                                                         // 2
                    dlg.Properties.AddButton(null, "Select None");                                                        // 3
                    dlg.Properties.Build();
                    dlg.Properties.PropertyClicked += MappingProperties_PropertyClicked;

                    dlg.ShowDialogAsync(null, (r) =>
                    {
                        if (r == DialogResult.OK)
                        {
                            var keysBool = dlg.Properties.GetPropertyValue <bool[]>(1);

                            src.keys = 0ul;
                            for (int i = 0; i < keysBool.Length; i++)
                            {
                                if (keysBool[i])
                                {
                                    src.keys |= (1ul << i);
                                }
                            }

                            UpdateListView();
                        }
                    });
                }
                else
                {
                    PlatformUtils.Beep();
                }
            }
        }
Example #5
0
        private void ShowConvertTempoDialogAsync(bool conversionNeeded, Action <bool> callback)
        {
            if (conversionNeeded)
            {
                const string label = "You changed the BPM enough so that the number of frames in a note has changed. What do you want to do?";

                var messageDlg = new PropertyDialog("Tempo Conversion", 400, true, false);
                messageDlg.Properties.AddLabel(null, label, true);                                                                                                                                                                                               // 0
                messageDlg.Properties.AddRadioButton(PlatformUtils.IsMobile ? label : null, "Resize notes to reflect the new BPM. This is the most sensible option if you just want to change the tempo of the song.", true);                                    // 1
                messageDlg.Properties.AddRadioButton(PlatformUtils.IsMobile ? label : null, "Leave the notes exactly where they are, just move the grid lines around the notes. This option is useful if you want to change how the notes are grouped.", false); // 2
                messageDlg.Properties.SetPropertyVisible(0, PlatformUtils.IsDesktop);
                messageDlg.Properties.Build();
                messageDlg.ShowDialogAsync(null, (r) =>
                {
                    callback(messageDlg.Properties.GetPropertyValue <bool>(1));
                });
            }
            else
            {
                callback(false);
            }
        }
Example #6
0
        public Project ShowDialog(FamiStudioForm parent)
        {
            var project = (Project)null;

            if (dialog != null)
            {
                // This is only ran in desktop and this isnt really async, so its ok.
                dialog.ShowDialogAsync(parent, (r) =>
                {
                    if (r == DialogResult.OK)
                    {
                        var expansionMask      = GetExpansionMask(dialog.Properties.GetPropertyValue <bool[]>(4));
                        var polyphony          = dialog.Properties.GetSelectedIndex(0);
                        var measuresPerPattern = dialog.Properties.GetPropertyValue <int>(1);
                        var velocityAsVolume   = dialog.Properties.GetPropertyValue <bool>(2);
                        var pal = expansionMask != ExpansionType.NoneMask ? false : dialog.Properties.GetPropertyValue <bool>(3);

                        project = new MidiFileReader().Load(filename, expansionMask, pal, channelSources, velocityAsVolume, polyphony, measuresPerPattern);
                    }
                });
            }

            return(project);
        }
 public void ShowDialogAsync(FamiStudioForm parent, Action <DialogResult> callback)
 {
     dialog.ShowDialogAsync(parent, callback);
 }
        public void ShowDialogAsync(Action <string> callback)
        {
            dialog.ShowDialogAsync(famistudio.MainForm, (r) =>
            {
                if (r == DialogResult.OK)
                {
                    if (saveMode)
                    {
                        var userProjectIdx = dialog.Properties.GetSelectedIndex(0);
                        var filename       = "";

                        // New file requested.
                        if (userProjectIdx == userProjects.Count - 1)
                        {
                            filename = dialog.Properties.GetPropertyValue <string>(1);
                        }
                        else
                        {
                            filename = userProjects[userProjectIdx];
                        }

                        if (!string.IsNullOrEmpty(filename))
                        {
                            filename = Path.Combine(PlatformUtils.UserProjectsDirectory, $"{filename}.fms");
                            callback(filename);
                        }
                    }
                    else
                    {
                        if (storageFilename != null)
                        {
                            callback(storageFilename);
                            return;
                        }

                        var userProjectIdx = dialog.Properties.GetSelectedIndex(0);
                        if (userProjectIdx >= 0)
                        {
                            var filename = GetUserProjectFilename(userProjects[userProjectIdx]);
                            callback(filename);
                            return;
                        }

                        var demoProjectIdx = dialog.Properties.GetSelectedIndex(1);
                        if (demoProjectIdx >= 0)
                        {
                            // Save to temporary file.
                            var tempFilename = Path.Combine(Path.GetTempPath(), "Temp.fms");

                            using (var s = Assembly.GetExecutingAssembly().GetManifestResourceStream($"FamiStudio.{demoProjects[demoProjectIdx]}.fms"))
                            {
                                var buffer = new byte[(int)s.Length];
                                s.Read(buffer, 0, (int)s.Length);
                                File.WriteAllBytes(tempFilename, buffer);
                            }

                            callback(tempFilename);
                            File.Delete(tempFilename);
                            return;
                        }
                    }
                }
            });
        }