protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (isDraggingInstrument) { if (ClientRectangle.Contains(e.X, e.Y)) { var buttonIdx = GetButtonAtCoord(e.X, e.Y, out var subButtonType); var instrumentSrc = instrumentDrag; var instrumentDst = buttonIdx >= 0 && buttons[buttonIdx].type == ButtonType.Instrument ? buttons[buttonIdx].instrument : null; if (instrumentSrc != instrumentDst && instrumentSrc != null && instrumentDst != null && instrumentSrc.ExpansionType == instrumentDst.ExpansionType) { if (envelopeDragIdx == -1) { if (PlatformUtils.MessageBox($"Are you sure you want to replace all notes of instrument '{instrumentDst.Name}' with '{instrumentSrc.Name}'?", "Replace intrument", MessageBoxButtons.YesNo) == DialogResult.Yes) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.ReplaceInstrument(instrumentDst, instrumentSrc); App.UndoRedoManager.EndTransaction(); InstrumentReplaced?.Invoke(instrumentDst); } } else { if (PlatformUtils.MessageBox($"Are you sure you want to copy the {Envelope.EnvelopeStrings[envelopeDragIdx]} envelope of instrument '{instrumentSrc.Name}' to '{instrumentDst.Name}'?", "Copy Envelope", MessageBoxButtons.YesNo) == DialogResult.Yes) { App.UndoRedoManager.BeginTransaction(TransactionScope.Instrument, instrumentDst.Id); instrumentDst.Envelopes[envelopeDragIdx] = instrumentSrc.Envelopes[envelopeDragIdx].Clone(); App.UndoRedoManager.EndTransaction(); InstrumentEdited?.Invoke(instrumentDst, envelopeDragIdx); Invalidate(); } } } } else { InstrumentDraggedOutside(instrumentDrag, PointToScreen(new Point(e.X, e.Y))); } Capture = false; } CancelDrag(); }
public void Paste() { if (!IsSelectionValid()) { return; } var mergeInstruments = ClipboardUtils.ContainsMissingInstruments(App.Project, false); bool createMissingInstrument = false; if (mergeInstruments) { createMissingInstrument = PlatformUtils.MessageBox($"You are pasting notes referring to unknown instruments. Do you want to create the missing instrument?", "Paste", MessageBoxButtons.YesNo) == DialogResult.Yes; } App.UndoRedoManager.BeginTransaction(createMissingInstrument ? TransactionScope.Project : TransactionScope.Song, Song.Id); var patterns = ClipboardUtils.LoadPatterns(App.Project, Song, createMissingInstrument); if (patterns == null) { App.UndoRedoManager.AbortTransaction(); return; } for (int i = 0; i < patterns.GetLength(0); i++) { for (int j = 0; j < patterns.GetLength(1); j++) { var pattern = patterns[i, j]; if (pattern != null && (i + minSelectedPatternIdx) < Song.Length && pattern.ChannelType < Song.Channels.Length && pattern.ChannelType == Song.Channels[pattern.ChannelType].Type) { Song.Channels[pattern.ChannelType].PatternInstances[i + minSelectedPatternIdx] = pattern; } } } App.UndoRedoManager.EndTransaction(); PatternsPasted?.Invoke(); ConditionalInvalidate(); }
private void ExportRom() { var props = dialog.GetPropertyPage((int)ExportFormat.Rom); var songIds = GetSongIds(props.GetPropertyValue <bool[]>(4)); if (songIds.Length > RomFileBase.MaxSongs) { PlatformUtils.MessageBox($"Please select {RomFileBase.MaxSongs} songs or less.", "ROM Export", MessageBoxButtons.OK); return; } if (props.GetPropertyValue <string>(0) == "NES ROM") { var filename = lastExportFilename != null ? lastExportFilename : PlatformUtils.ShowSaveFileDialog("Export ROM File", "NES ROM (*.nes)|*.nes", ref Settings.LastExportFolder); if (filename != null) { var rom = new RomFile(); rom.Save( project, filename, songIds, props.GetPropertyValue <string>(1), props.GetPropertyValue <string>(2), props.GetPropertyValue <string>(3) == "PAL"); lastExportFilename = filename; } } else { var filename = lastExportFilename != null ? null : PlatformUtils.ShowSaveFileDialog("Export Famicom Disk", "FDS Disk (*.fds)|*.fds", ref Settings.LastExportFolder); if (filename != null) { var fds = new FdsFile(); fds.Save( project, filename, songIds, props.GetPropertyValue <string>(1), props.GetPropertyValue <string>(2)); lastExportFilename = filename; } } }
private void ExportRom() { var props = dialog.GetPropertyPage((int)ExportFormat.Rom); var songIds = GetSongIds(props.GetPropertyValue <bool[]>(2)); if (songIds.Length > RomFile.MaxSongs) { PlatformUtils.MessageBox("Please select 8 songs or less.", "ROM Export", MessageBoxButtons.OK); return; } var filename = PlatformUtils.ShowSaveFileDialog("Export ROM File", "NES ROM (*.nes)|*.nes"); if (filename != null) { RomFile.Save(project, filename, songIds, props.GetPropertyValue <string>(0), props.GetPropertyValue <string>(1)); } }
protected override void OnMouseDoubleClick(MouseEventArgs e) { base.OnMouseDoubleClick(e); var buttonIdx = GetButtonAtCoord(e.X, e.Y, out var subButtonType); if (buttonIdx >= 0) { var button = buttons[buttonIdx]; if (button.type == ButtonType.ProjectSettings) { var project = App.Project; var dlg = new PropertyDialog(PointToScreen(new Point(e.X, e.Y)), 280, true); dlg.Properties.AddString("Title :", project.Name, 31); // 0 dlg.Properties.AddString("Author :", project.Author, 31); // 1 dlg.Properties.AddString("Copyright :", project.Copyright, 31); // 2 dlg.Properties.AddStringList("Expansion Audio:", Project.ExpansionNames, project.ExpansionAudioName); // 3 dlg.Properties.Build(); if (dlg.ShowDialog() == DialogResult.OK) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); project.Name = dlg.Properties.GetPropertyValue <string>(0); project.Author = dlg.Properties.GetPropertyValue <string>(1); project.Copyright = dlg.Properties.GetPropertyValue <string>(2); var expansion = Array.IndexOf(Project.ExpansionNames, dlg.Properties.GetPropertyValue <string>(3)); if (expansion != project.ExpansionAudio) { if (project.ExpansionAudio == Project.ExpansionNone || PlatformUtils.MessageBox($"Switching expansion audio will delete all instruments and channels using the old expansion?", "Change expansion audio", MessageBoxButtons.YesNo) == DialogResult.Yes) { App.StopInstrumentPlayer(); project.SetExpansionAudio(expansion); ExpansionAudioChanged?.Invoke(); App.StartInstrumentPlayer(); Reset(); } } App.UndoRedoManager.EndTransaction(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Song) { var song = button.song; var dlg = new PropertyDialog(PointToScreen(new Point(e.X, e.Y)), 200, true); dlg.Properties.AddColoredString(song.Name, song.Color); // 0 dlg.Properties.AddIntegerRange("Tempo :", song.Tempo, 32, 255); // 1 dlg.Properties.AddIntegerRange("Speed :", song.Speed, 1, 31); // 2 dlg.Properties.AddIntegerRange("Pattern Length :", song.PatternLength, 16, 256); // 3 dlg.Properties.AddDomainRange("Bar Length :", GenerateBarLengths(song.PatternLength), song.BarLength); // 4 dlg.Properties.AddIntegerRange("Song Length :", song.Length, 1, 128); // 5 dlg.Properties.AddColor(song.Color); // 6 dlg.Properties.Build(); dlg.Properties.PropertyChanged += Properties_PropertyChanged; if (dlg.ShowDialog() == DialogResult.OK) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Stop(); App.Seek(0); var newName = dlg.Properties.GetPropertyValue <string>(0); if (App.Project.RenameSong(song, newName)) { song.Color = dlg.Properties.GetPropertyValue <System.Drawing.Color>(6); song.Tempo = dlg.Properties.GetPropertyValue <int>(1); song.Speed = dlg.Properties.GetPropertyValue <int>(2); song.SetLength(dlg.Properties.GetPropertyValue <int>(5)); song.SetPatternLength(dlg.Properties.GetPropertyValue <int>(3)); song.SetBarLength(dlg.Properties.GetPropertyValue <int>(4)); SongModified?.Invoke(song); App.UndoRedoManager.EndTransaction(); RefreshButtons(); } else { App.UndoRedoManager.AbortTransaction(); SystemSounds.Beep.Play(); } ConditionalInvalidate(); } } else if (button.type == ButtonType.Instrument && button.instrument != null) { var instrument = button.instrument; if (subButtonType == SubButtonType.Max) { var dlg = new PropertyDialog(PointToScreen(new Point(e.X, e.Y)), 160, true); dlg.Properties.AddColoredString(instrument.Name, instrument.Color); // 0 dlg.Properties.AddColor(instrument.Color); // 1 dlg.Properties.AddBoolean("Relative pitch:", instrument.Envelopes[Envelope.Pitch].Relative); // 2 dlg.Properties.Build(); if (dlg.ShowDialog() == DialogResult.OK) { var newName = dlg.Properties.GetPropertyValue <string>(0); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); if (App.Project.RenameInstrument(instrument, newName)) { instrument.Color = dlg.Properties.GetPropertyValue <System.Drawing.Color>(1); instrument.Envelopes[Envelope.Pitch].Relative = dlg.Properties.GetPropertyValue <bool>(2); InstrumentColorChanged?.Invoke(instrument); RefreshButtons(); ConditionalInvalidate(); App.UndoRedoManager.EndTransaction(); } else { App.UndoRedoManager.AbortTransaction(); SystemSounds.Beep.Play(); } } } } } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); bool left = e.Button.HasFlag(MouseButtons.Left); bool middle = e.Button.HasFlag(MouseButtons.Middle) || (e.Button.HasFlag(MouseButtons.Left) && ModifierKeys.HasFlag(Keys.Alt)); bool right = e.Button.HasFlag(MouseButtons.Right); var buttonIdx = GetButtonAtCoord(e.X, e.Y, out var subButtonType); if (buttonIdx >= 0) { var button = buttons[buttonIdx]; if (left) { if (button.type == ButtonType.SongHeader) { if (subButtonType == SubButtonType.Add) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.CreateSong(); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Song) { if (button.song != selectedSong) { selectedSong = button.song; SongSelected?.Invoke(selectedSong); ConditionalInvalidate(); } } else if (button.type == ButtonType.InstrumentHeader) { if (subButtonType == SubButtonType.Add) { var instrumentType = Project.ExpansionNone; if (App.Project.NeedsExpansionInstruments) { var expNames = new[] { Project.ExpansionNames[Project.ExpansionNone], App.Project.ExpansionAudioName }; var dlg = new PropertyDialog(PointToScreen(new Point(e.X, e.Y)), 240, true); dlg.Properties.AddStringList("Expansion:", expNames, Project.ExpansionNames[Project.ExpansionNone]); // 0 dlg.Properties.Build(); if (dlg.ShowDialog() == DialogResult.OK) { instrumentType = dlg.Properties.GetPropertyValue <string>(0) == Project.ExpansionNames[Project.ExpansionNone] ? Project.ExpansionNone : App.Project.ExpansionAudio; } else { return; } } App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.CreateInstrument(instrumentType); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } if (subButtonType == SubButtonType.LoadInstrument) { var filename = PlatformUtils.ShowOpenFileDialog("Open File", "Fami Tracker Instrument (*.fti)|*.fti"); if (filename != null) { App.UndoRedoManager.BeginTransaction(TransactionScope.Project); var instrument = FamitrackerInstrumentFile.CreateFromFile(App.Project, filename); if (instrument == null) { App.UndoRedoManager.AbortTransaction(); } else { App.UndoRedoManager.EndTransaction(); } } RefreshButtons(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Instrument) { selectedInstrument = button.instrument; if (selectedInstrument != null) { instrumentDrag = selectedInstrument; mouseDragY = e.Y; } if (subButtonType == SubButtonType.Volume) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Volume); envelopeDragIdx = Envelope.Volume; } else if (subButtonType == SubButtonType.Pitch) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Pitch); envelopeDragIdx = Envelope.Pitch; } else if (subButtonType == SubButtonType.Arpeggio) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Arpeggio); envelopeDragIdx = Envelope.Arpeggio; } else if (subButtonType == SubButtonType.DPCM) { InstrumentEdited?.Invoke(selectedInstrument, Envelope.Max); } else if (subButtonType == SubButtonType.DutyCycle) { selectedInstrument.DutyCycle = (selectedInstrument.DutyCycle + 1) % selectedInstrument.DutyCycleRange; } InstrumentSelected?.Invoke(selectedInstrument); ConditionalInvalidate(); } } else if (right) { if (button.type == ButtonType.Song && App.Project.Songs.Count > 1) { var song = button.song; if (PlatformUtils.MessageBox($"Are you sure you want to delete '{song.Name}' ?", "Delete song", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool selectNewSong = song == selectedSong; App.Stop(); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.DeleteSong(song); if (selectNewSong) { selectedSong = App.Project.Songs[0]; } SongSelected?.Invoke(selectedSong); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } } else if (button.type == ButtonType.Instrument && button.instrument != null) { var instrument = button.instrument; if (subButtonType == SubButtonType.Arpeggio || subButtonType == SubButtonType.Pitch || subButtonType == SubButtonType.Volume) { int envType = Envelope.Volume; switch (subButtonType) { case SubButtonType.Arpeggio: envType = Envelope.Arpeggio; break; case SubButtonType.Pitch: envType = Envelope.Pitch; break; } App.UndoRedoManager.BeginTransaction(TransactionScope.Instrument, instrument.Id); instrument.Envelopes[envType].Length = 0; App.UndoRedoManager.EndTransaction(); ConditionalInvalidate(); } else if (subButtonType == SubButtonType.Max) { if (PlatformUtils.MessageBox($"Are you sure you want to delete '{instrument.Name}' ? All notes using this instrument will be deleted.", "Delete intrument", MessageBoxButtons.YesNo) == DialogResult.Yes) { bool selectNewInstrument = instrument == selectedInstrument; App.StopInstrumentNoteAndWait(); App.UndoRedoManager.BeginTransaction(TransactionScope.Project); App.Project.DeleteInstrument(instrument); if (selectNewInstrument) { selectedInstrument = App.Project.Instruments.Count > 0 ? App.Project.Instruments[0] : null; } SongSelected?.Invoke(selectedSong); InstrumentDeleted?.Invoke(instrument); App.UndoRedoManager.EndTransaction(); RefreshButtons(); ConditionalInvalidate(); } } } } } if (middle) { mouseLastY = e.Y; } }