Skip to content

Commit

Permalink
- Restored automatic 'Save Template' when 'Import Package' is used.
Browse files Browse the repository at this point in the history
- Implemented reusable generic code for Low Bass Tuning Fix.
- Added automatic Low Bass Tuning Fix to 'Import Package' (see the 'General Config').
- Autosave the ‘Fixed’ low bass tuning definition to TuningDefinition.xml file.
- Added additional error checking to tuning and frequency for bass tuning.
- Restored interconnecting EH between frequency and offset displays.
- Auto reload the tuning definitions.
- Linked the 'Tuning Editor' display to the currently selected tuning combo in 'Add Arrangements' for improved efficiency.
- Code restructuring and improved functionality of 'Add Arrangements'  and 'Creator' forms.
- Added automatic repair of Multitone Exceptions when 'Importing Packages' into 'CDLC Creator' (see the 'General Config').
- Added progress bar to 'Tones Import'.
- Improved DLC Key validation to return a minimum key length of (6), and maximum key length of (30).
  • Loading branch information
cozy1 committed Feb 16, 2017
1 parent 5829b2b commit 150afd2
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 150 deletions.
11 changes: 6 additions & 5 deletions RocksmithTookitGUI/Config/GeneralConfig.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

204 changes: 112 additions & 92 deletions RocksmithTookitGUI/DLCPackageCreator/ArrangementForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
using RocksmithToolkitLib.Xml;
using RocksmithToolkitLib.XmlRepository;

// objective is to do most work with the arrangment as memory variable
// do most work with the arrangment as memory variable

namespace RocksmithToolkitGUI.DLCPackageCreator
{
public partial class ArrangementForm : Form
{
public bool EditMode;
private Arrangement _arrangement;
private bool _bassFix;
private bool _dirty;
private GameVersion _gameVersion;
private bool _isBassFixed;
private DLCPackageCreator _parentControl;
private ToolTip _toolTip = new ToolTip();
private Song2014 _xmlSong;
Expand All @@ -42,6 +40,7 @@ public ArrangementForm(DLCPackageCreator control, GameVersion gameVersion)
ArrangementType = ArrangementType.Guitar
}, control, gameVersion)
{
EditMode = false;
Console.WriteLine("Debug");
}

Expand Down Expand Up @@ -121,7 +120,7 @@ public ArrangementForm(Arrangement arrangement, DLCPackageCreator control, GameV
// Update tuningComboBox
if (guitarebass)
FillTuningCombo(selectedType, _gameVersion);
FillTuningCombo(_gameVersion);
}; //END EH arrangementTypeCombo.SelectedValueChanged

Expand All @@ -144,14 +143,8 @@ public ArrangementForm(Arrangement arrangement, DLCPackageCreator control, GameV

#endregion

// do a quick Low Bass Tuning check
if (!String.IsNullOrEmpty(arrangement.SongXml.File) && arrangement.ArrangementType == ArrangementType.Bass)
{

}

SetupTones(arrangement);
Arrangement = arrangement; // update form using SET action
Arrangement = arrangement; // update form using SET action
}

public Arrangement Arrangement
Expand Down Expand Up @@ -231,7 +224,6 @@ public bool LoadArrangementData(string xmlfilepath)
Arrangement.SongXml.File = xmlfilepath;

// Song Info
// TODO: get song info from json or hsan file (would be better than from xml)
if (!ReferenceEquals(_xmlSong, null))
{
var defaultAuthor = ConfigRepository.Instance()["general_defaultauthor"].Trim();
Expand Down Expand Up @@ -400,6 +392,7 @@ public bool LoadXmlArrangement(string xmlFilePath)
chkMetronome.Checked = Equals(_xmlSong.ArrangementProperties.Metronome, 2);
Arrangement.ArrangementPropeties = _xmlSong.ArrangementProperties;
Arrangement.CapoFret = _xmlSong.Capo;
Arrangement.TuningStrings = _xmlSong.Tuning;

if (!String.IsNullOrEmpty(_xmlSong.CentOffset))
Arrangement.TuningPitch = Convert.ToDouble(_xmlSong.CentOffset).Cents2Frequency();
Expand All @@ -411,6 +404,7 @@ public bool LoadXmlArrangement(string xmlFilePath)
if (arr.Contains("guitar") || arr.Contains("lead") || arr.Contains("rhythm") || arr.Contains("combo"))
{
cmbArrangementType.SelectedItem = ArrangementType.Guitar;
Arrangement.ArrangementType = ArrangementType.Guitar;

if (arr.Contains("combo"))
{
Expand All @@ -431,17 +425,9 @@ public bool LoadXmlArrangement(string xmlFilePath)
else if (arr.Contains("bass"))
{
cmbArrangementType.SelectedItem = ArrangementType.Bass;
Arrangement.ArrangementType = ArrangementType.Bass;
chkBassPicked.Checked = Equals(_xmlSong.ArrangementProperties.BassPick, 1);

if (_gameVersion != GameVersion.RS2012)
{
RouteMask = RouteMask.Bass;
//Low tuning fix for bass, If lowest string is B and bass fix not applied TODO:applyonly when 'generate'
if (_xmlSong.Tuning.String0 < -4 && Arrangement.TuningPitch != 220)
_bassFix |= MessageBox.Show(@"The bass tuning may be too low. Apply Low Bass Tuning Fix?" + Environment.NewLine +
@"Note: The fix will revert if bass Arrangement is re-saved in EOF. ",
@"Warning ... Low Bass Tuning", MessageBoxButtons.YesNo) == DialogResult.Yes;
}
if (_gameVersion != GameVersion.RS2012) RouteMask = RouteMask.Bass;
}

if (_gameVersion != GameVersion.RS2012)
Expand All @@ -454,72 +440,13 @@ public bool LoadXmlArrangement(string xmlFilePath)
Arrangement.ToneD = _xmlSong.ToneD;
Arrangement.ToneMultiplayer = null;
SetupTones(Arrangement);

// Fix Low Bass Tuning
if (_bassFix)
{
if (Arrangement.TuningStrings == null)
{
// need to load tuning here from the xml Arrangement
Arrangement.TuningStrings = new TuningStrings();
Arrangement.TuningStrings = _xmlSong.Tuning;
}

if (!TuningFrequency.ApplyBassFix(Arrangement))
MessageBox.Show("This bass Arrangement is already at 220Hz pitch. ", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);

_xmlSong.Tuning = Arrangement.TuningStrings;
_bassFix = false;
}
}

// Setup tuning
ArrangementType selectedType;
if (_xmlSong.Arrangement.ToLower() == "bass")
selectedType = ArrangementType.Bass;
else
selectedType = ArrangementType.Guitar;

FillTuningCombo(selectedType, _gameVersion);

// find tuning in tuningComboBox list and make selection
int foundTuning = -1;
for (int tcbIndex = 0; tcbIndex < cmbTuningName.Items.Count; tcbIndex++)
{
cmbTuningName.SelectedIndex = tcbIndex;
TuningDefinition tuning = (TuningDefinition)cmbTuningName.Items[tcbIndex];
if (tuning.Tuning == _xmlSong.Tuning)
{
foundTuning = tcbIndex;
break;
}
}
if (Arrangement.ArrangementType == ArrangementType.Bass)
FixBassTuning();

// TODO: testing toolkit's AI
// toolkit is pretty smart now so let it automatically set tuning if found
if (foundTuning == -1) // && selectedType != ArrangementType.Bass)
{
cmbTuningName.SelectedIndex = 0;
ShowTuningForm(selectedType, new TuningDefinition(_xmlSong.Tuning, _gameVersion)); //FIXME: Don't use this for QuickAdd call
}

// E Standard, Drop D, and Open E tuning are now the same for both guitar and bass
//if (foundTuning == -1 && selectedType == ArrangementType.Bass)
//{
// tuningComboBox.SelectedIndex = 0;
// MessageBox.Show("Toolkit was not able to automatically set tuning for" + Environment.NewLine +
// "Bass Arrangement: " + Path.GetFileName(xmlFilePath) + Environment.NewLine +
// "Use the tuning selector combobox or Tuning Editor" + Environment.NewLine +
// "to customize bass tuning (as defined for six strings). ", DLCPackageCreator.MESSAGEBOX_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
//}

cmbTuningName.Refresh();
Arrangement.Tuning = cmbTuningName.SelectedItem.ToString();
Arrangement.TuningStrings = _xmlSong.Tuning;

// bass hack cross check
if (Arrangement.Tuning.Contains("Fixed"))
txtFrequency.Text = "220";
SelectTuningName();
CheckTuning();

// save converted RS1 to RS2014 Song2014 XML
if (version == GameVersion.None)
Expand Down Expand Up @@ -567,7 +494,7 @@ private void FillToneCombo(ComboBox combo, IEnumerable<string> toneNames, bool i
}
}

private void FillTuningCombo(ArrangementType arrangementType, GameVersion gameVersion)
private void FillTuningCombo(GameVersion gameVersion)
{
cmbTuningName.Items.Clear();

Expand Down Expand Up @@ -709,23 +636,27 @@ private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tunin
return;
}

bool addNew;
TuningDefinition formTuning;
using (var form = new TuningForm())
// get the latest comments from the XML to check if previously bass fixed
if (!String.IsNullOrEmpty(Arrangement.SongXml.File))
{
// get the latest comments from the XML
var xmlComments = Song2014.ReadXmlComments(Arrangement.SongXml.File);
var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || txtFrequency.Text == "220";
var isBassFixed = xmlComments.Any(xComment => xComment.ToString().Contains("Low Bass Tuning Fixed")) || Convert.ToDouble(txtFrequency.Text) == 220.00;

if (isBassFixed && !tuning.UIName.Contains("Fixed"))
{
// UIName may contain spaces, where as Name contains no spaces
tuning.UIName = String.Format("{0} Fixed", tuning.UIName);
tuning.Name = tuning.UIName.ReplaceSpaceWith("");
tuning.Custom = true;
TuningDefinitionRepository.Instance.Add(tuning, true);
TuningDefinitionRepository.Instance.Save(true);
}
}

bool addNew;
TuningDefinition formTuning;
using (var form = new TuningForm())
{
form.Tuning = tuning;
form.IsBass = selectedType == ArrangementType.Bass;

Expand All @@ -752,7 +683,7 @@ private void ShowTuningForm(ArrangementType selectedType, TuningDefinition tunin
}
}

FillTuningCombo(selectedType, _gameVersion);
FillTuningCombo(_gameVersion);

int foundTuning = -1;
cmbTuningName.SelectedIndex = -1;
Expand Down Expand Up @@ -910,6 +841,12 @@ private void ArrangementForm_Load(object sender, EventArgs e)
{
btnBrowseXml.Enabled = false;
txtXmlPath.ReadOnly = true;

if (Arrangement.ArrangementType == ArrangementType.Bass)
FixBassTuning();

SelectTuningName();
CheckTuning();
}
}

Expand Down Expand Up @@ -989,6 +926,9 @@ private void btnOk_Click(object sender, EventArgs e)
}
}

if (!CheckTuning())
return;

LoadArrangementData(xmlfilepath);
Globals.DefaultProjectDir = Path.GetDirectoryName(xmlfilepath);
DialogResult = DialogResult.OK;
Expand Down Expand Up @@ -1018,6 +958,86 @@ private void txtFrequency_TextChanged(object sender, EventArgs e)
var bFreq = ((CueTextBox)sender).Name.StartsWith("txtFrequency");
UpdateCentOffset(bFreq ? "HZ" : "c");
}

private bool FixBassTuning()

This comment has been minimized.

Copy link
@L0FKA

L0FKA Feb 17, 2017

Member

I'd like to have tests for the low tuning fix logic so we won't mess it up with time >___>

This comment has been minimized.

Copy link
@cozy1

cozy1 Feb 17, 2017

Author Contributor

Good idea. I'd like to have tests for whole toolkit, too. ;)

This comment has been minimized.

Copy link
@L0FKA

L0FKA Feb 17, 2017

Member

Love the idea too, "kill it (legacy code) with fire!" 🔥🔥🔥

This comment has been minimized.

Copy link
@cozy1

cozy1 Feb 18, 2017

Author Contributor

I got very tired of looking at 'old' Pascal code format. 👍

{
// fix old toolkit behavior
if (Arrangement.TuningStrings == null)
{
Arrangement.TuningStrings = new TuningStrings();
return false;
}

var bassFix = false;
//Low tuning fix for bass, If lowest string is B and bass fix not applied
if (Arrangement.TuningStrings.String0 < -4 && Arrangement.TuningPitch != 220.00)
if (ConfigRepository.Instance().GetBoolean("creator_fixlowbass"))
bassFix = true;
else
bassFix |= MessageBox.Show(@"The bass tuning may be too low. Apply Low Bass Tuning Fix?" + Environment.NewLine + @"Note: The fix may revert if bass Arrangement is re-saved in EOF. ", @"Warning ... Low Bass Tuning", MessageBoxButtons.YesNo) == DialogResult.Yes;

// Fix Low Bass Tuning
if (bassFix && TuningFrequency.ApplyBassFix(Arrangement))
{
Arrangement.TuningStrings = Song2014.LoadFromFile(Arrangement.SongXml.File).Tuning;
Arrangement.TuningPitch = 220.00;
txtFrequency.Text = "220.00";
return true;
}

return false;
}

private void SelectTuningName()
{
// find tuning in tuningComboBox list and make selection
int foundTuning = -1;
for (int tcbIndex = 0; tcbIndex < cmbTuningName.Items.Count; tcbIndex++)
{
cmbTuningName.SelectedIndex = tcbIndex;
TuningDefinition tuning = (TuningDefinition)cmbTuningName.Items[tcbIndex];
if (tuning.Tuning == Arrangement.TuningStrings)
{
foundTuning = tcbIndex;
break;
}
}

// TODO: testing toolkit's AI
// toolkit is pretty smart now so let it automatically set tuning if found
// E Standard, Drop D, and Open E tuning are now the same for both guitar and bass
if (foundTuning == -1)
{
cmbTuningName.SelectedIndex = 0;
var selectedType = ((ArrangementType)cmbArrangementType.SelectedItem);
ShowTuningForm(selectedType, new TuningDefinition(Arrangement.TuningStrings, _gameVersion));
}
}

private bool CheckTuning()
{
// for now just check bass arrangements
if (Arrangement.ArrangementType != ArrangementType.Bass)
return true;

// Error check 220.00 and Fixed
TuningDefinition tuning = (TuningDefinition)cmbTuningName.SelectedItem;
Arrangement.Tuning = tuning.UIName;
Arrangement.TuningStrings = tuning.Tuning;
UpdateCentOffset();

if ((Arrangement.TuningPitch == 220.00 && !Arrangement.Tuning.Contains("Fixed")) ||
(Arrangement.TuningPitch != 220.00 && Arrangement.Tuning.Contains("Fixed")))
{
MessageBox.Show(@"The bass tuning name and frequency are not set correctly." + Environment.NewLine + Environment.NewLine +
@"Tuning name must contain 'Fixed' when frequency is 220Hz" + Environment.NewLine +
@"and name may not contain 'Fixed' if frequency is not 220Hz.", @"Error ... Low Bass Tuning", MessageBoxButtons.OK);
return false;
}

return true;
}

}
}

Loading

0 comments on commit 150afd2

Please sign in to comment.