private void SongProfileSaveButton_Click(object sender, EventArgs e) { if (trackSelectionManager.FileName != null) { trackSelectionManager.SaveTrackManager(); } }
private void ReloadButton_Click(object sender, EventArgs e) { // First grab the Track Filtering settings for our current track // Re-load the same midi track from file // And re-apply those settings // I don't think getting the settings is that easy but we'll try // Oh hey it can be. var data = trackSelectionManager.GetTrackSelectionData(); player.LoadFile(currentTrackName); trackSelectionManager.SetTrackSelectionData(data); trackSelectionManager.SaveTrackManager(); if (trackSelectionForm != null && !trackSelectionForm.IsDisposed && trackSelectionForm.IsHandleCreated) // Everything I can think to check { trackSelectionForm.Invoke((MethodInvoker) delegate { trackSelectionForm.Refresh(); }); // Invoking just in case this is on a diff thread somehow } Refresh(); }
private void savePartitionsButton_Click(object sender, EventArgs e) { if (tsm.MidiTracks.Values.Where(t => t.Active).Count() > 0) { var namingForm = new TrackNamingForm(Path.GetFileNameWithoutExtension(tsm.FileName)); namingForm.ShowDialog(this); if (namingForm.DialogResult == DialogResult.OK) { if (namingForm.textBoxPartName.Text == "Partition Name" || namingForm.textBoxPartName.Text.Trim() == "") { MessageBox.Show("Please name your partition"); } else { if (index.PartitionNames.Contains(namingForm.textBoxPartName.Text)) { MessageBox.Show("That name already exists"); } else { if (!Regex.IsMatch(namingForm.textBoxPartName.Text, "^([a-zA-Z0-9][a-zA-Z0-9 -]*[a-zA-Z0-9])$")) { MessageBox.Show("That name contains invalid characters"); } else { index.PartitionNames.Add(namingForm.textBoxPartName.Text); //if (trackConverter == null) //{ var converter = new LuteMod.Converter.MordhauConverter(); int firstInstrument = ConfigManager.GetIntegerProperty(PropertyItem.Instrument); // Step 1, load solo lute into track 0 - this profile should always exist // Actually, all of the first 4 instruments get loaded in, under the same ID we use in lutebot. Convenient. for (int i = 0; i < 4; i++) { int oldInstrument = ConfigManager.GetIntegerProperty(PropertyItem.Instrument); if (tsm.DataDictionary.ContainsKey(i)) { if (oldInstrument != i) { ConfigManager.SetProperty(PropertyItem.Instrument, i.ToString()); Instrument target = Instrument.Prefabs[i]; bool soundEffects = !target.Name.StartsWith("Mordhau", true, System.Globalization.CultureInfo.InvariantCulture); ConfigManager.SetProperty(PropertyItem.SoundEffects, soundEffects.ToString()); ConfigManager.SetProperty(PropertyItem.LowestNoteId, target.LowestSentNote.ToString()); ConfigManager.SetProperty(PropertyItem.AvaliableNoteCount, target.NoteCount.ToString()); ConfigManager.SetProperty(PropertyItem.NoteCooldown, target.NoteCooldown.ToString()); ConfigManager.SetProperty(PropertyItem.LowestPlayedNote, target.LowestPlayedNote.ToString()); ConfigManager.SetProperty(PropertyItem.ForbidsChords, target.ForbidsChords.ToString()); tsm.UpdateTrackSelectionForInstrument(oldInstrument); player.mordhauOutDevice.UpdateNoteIdBounds(); } converter.Range = ConfigManager.GetIntegerProperty(PropertyItem.AvaliableNoteCount); converter.LowNote = ConfigManager.GetIntegerProperty(PropertyItem.LowestPlayedNote); converter.IsConversionEnabled = true; converter.SetDivision(player.sequence.Division); converter.SetPartitionTempo(player.sequence.FirstTempo); converter.AddTrack(); converter.SetEnabledTracksInTrack(i, tsm.MidiTracks.Values.ToList()); converter.SetEnabledMidiChannelsInTrack(i, tsm.MidiChannels.Values.ToList()); converter.FillTrack(i, player.ExtractMidiContent()); } } SaveManager.WriteSaveFile(Path.Combine(SaveManager.SaveFilePath, namingForm.textBoxPartName.Text), converter.GetPartitionToString()); index.SaveIndex(); PopulateIndexList(); // And put the instrument back if (ConfigManager.GetIntegerProperty(PropertyItem.Instrument) != firstInstrument) { int oldInstrument = ConfigManager.GetIntegerProperty(PropertyItem.Instrument); ConfigManager.SetProperty(PropertyItem.Instrument, firstInstrument.ToString()); Instrument target = Instrument.Prefabs[firstInstrument]; bool soundEffects = !target.Name.StartsWith("Mordhau", true, System.Globalization.CultureInfo.InvariantCulture); ConfigManager.SetProperty(PropertyItem.SoundEffects, soundEffects.ToString()); ConfigManager.SetProperty(PropertyItem.LowestNoteId, target.LowestSentNote.ToString()); ConfigManager.SetProperty(PropertyItem.AvaliableNoteCount, target.NoteCount.ToString()); ConfigManager.SetProperty(PropertyItem.NoteCooldown, target.NoteCooldown.ToString()); ConfigManager.SetProperty(PropertyItem.LowestPlayedNote, target.LowestPlayedNote.ToString()); ConfigManager.SetProperty(PropertyItem.ForbidsChords, target.ForbidsChords.ToString()); tsm.UpdateTrackSelectionForInstrument(oldInstrument); player.mordhauOutDevice.UpdateNoteIdBounds(); } //} //else //{ // SaveManager.WriteSaveFile(SaveManager.SaveFilePath + namingForm.textBoxPartName.Text, trackConverter.GetPartitionToString()); // index.SaveIndex(); // PopulateIndexList(); // trackConverter = null; //} // Lastly, save the settings in a midi file with the same name, in the same folder, for ease of sharing... // TODO: Consider storing these in appdata, and providing a button to access them. Both might get complicated if I make partition playlists // Actually... I think I will store them in appdata. var midFileName = Path.Combine(partitionMidiPath, namingForm.textBoxPartName.Text + ".mid"); if (File.Exists(midFileName)) { File.Delete(midFileName); } Directory.CreateDirectory(partitionMidiPath); Task.Run(() => tsm.SaveTrackManager(midFileName)); // Lutebot doesn't need this anytime soon - and shouldn't offer the option to load it until it exists anyway } } } } else if (namingForm.DialogResult == DialogResult.Yes) { // They wanted to just add it as a track if (trackConverter == null) { trackConverter = new LuteMod.Converter.MordhauConverter(); } // These ranges and settings only matter for FillTrack. So re-setting them each time isn't a problem trackConverter.Range = ConfigManager.GetIntegerProperty(PropertyItem.AvaliableNoteCount); trackConverter.LowNote = ConfigManager.GetIntegerProperty(PropertyItem.LowestPlayedNote); trackConverter.IsConversionEnabled = true; trackConverter.SetDivision(player.sequence.Division); // This one could be weird trackConverter.AddTrack(); trackConverter.SetEnabledTracksInTrack(trackConverter.GetTrackCount() - 1, tsm.MidiTracks.Values.ToList()); trackConverter.SetEnabledMidiChannelsInTrack(trackConverter.GetTrackCount() - 1, tsm.MidiChannels.Values.ToList()); trackConverter.FillTrack(trackConverter.GetTrackCount() - 1, player.ExtractMidiContent()); } } else { MessageBox.Show("The partition is empty"); } }