Skip to content

Commit 83f436d

Browse files
committed
Add Pitch Sync Mode setting and functionality
Introduces a new PitchSyncMode setting to Settings and SettingsFile, adds UI control in SettingsWindow, and updates PianoScrollViewOperation to synchronize pitch data when moving notes if PitchSyncMode is enabled. Also replaces hardcoded parameter boundary extension values with the configurable setting.
1 parent 68a353d commit 83f436d

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

TuneLab/Configs/Settings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ internal static class Settings
1919
public static NotifiableProperty<string> BackgroundImagePath { get; } = DefaultSettings.BackgroundImagePath;
2020
public static NotifiableProperty<double> BackgroundImageOpacity { get; } = DefaultSettings.BackgroundImageOpacity;
2121
public static NotifiableProperty<double> ParameterBoundaryExtension { get; } = DefaultSettings.ParameterBoundaryExtension;
22+
public static NotifiableProperty<bool> PitchSyncMode { get; } = new(DefaultSettings.PitchSyncMode);
2223
public static NotifiableProperty<string> PianoKeySamplesPath { get; } = DefaultSettings.PianoKeySamplesPath;
2324
public static NotifiableProperty<int> AutoSaveInterval { get; } = DefaultSettings.AutoSaveInterval;
2425
public static NotifiableProperty<int> BufferSize { get; } = DefaultSettings.BufferSize;
@@ -49,6 +50,7 @@ public static void Init(string path)
4950
BackgroundImagePath.Value = settingsFile.BackgroundImagePath;
5051
BackgroundImageOpacity.Value = settingsFile.BackgroundImageOpacity;
5152
ParameterBoundaryExtension.Value = settingsFile.ParameterBoundaryExtension;
53+
PitchSyncMode.Value = settingsFile.PitchSyncMode;
5254
PianoKeySamplesPath.Value = settingsFile.PianoKeySamplesPath;
5355
AutoSaveInterval.Value = settingsFile.AutoSaveInterval;
5456
BufferSize.Value = settingsFile.BufferSize;
@@ -69,6 +71,7 @@ public static void Save(string path)
6971
BackgroundImagePath = BackgroundImagePath,
7072
BackgroundImageOpacity = BackgroundImageOpacity,
7173
ParameterBoundaryExtension = ParameterBoundaryExtension,
74+
PitchSyncMode = PitchSyncMode.Value,
7275
PianoKeySamplesPath = PianoKeySamplesPath,
7376
AutoSaveInterval = AutoSaveInterval,
7477
BufferSize = BufferSize,

TuneLab/Configs/SettingsFile.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal class SettingsFile
1313
public string BackgroundImagePath { get; set; } = string.Empty;
1414
public double BackgroundImageOpacity { get; set; } = 0.5;
1515
public double ParameterBoundaryExtension { get; set; } = 5;
16+
public bool PitchSyncMode { get; set; } = false;
1617
public string PianoKeySamplesPath { get; set; } = string.Empty;
1718
public int AutoSaveInterval { get; set; } = 10;
1819
public int BufferSize { get; set; } = 1024;

TuneLab/UI/MainWindow/Editor/PianoWindow/PianoScrollView/PianoScrollView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,13 +875,13 @@ public void PasteAt(double pos)
875875
break;
876876
case PianoTool.Pitch:
877877
case PianoTool.Lock:
878-
Part.PasteAt(mParameterClipboard, pos, 5);
878+
Part.PasteAt(mParameterClipboard, pos, Settings.ParameterBoundaryExtension);
879879
Part.Commit();
880880
break;
881881
case PianoTool.Select:
882882
Part.PasteAt(mNoteClipboard, pos);
883883
Part.PasteAt(mVibratoClipboard, pos);
884-
Part.PasteAt(mParameterClipboard, pos, 5);
884+
Part.PasteAt(mParameterClipboard, pos, Settings.ParameterBoundaryExtension);
885885
Part.Commit();
886886
break;
887887
}

TuneLab/UI/MainWindow/Editor/PianoWindow/PianoScrollView/PianoScrollViewOperation.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,17 +1576,51 @@ public void Move(Avalonia.Point point, bool alt, bool shift)
15761576
part.DiscardTo(mHead);
15771577
part.BeginMergeReSegment();
15781578
part.Notes.ListModified.BeginMerge();
1579+
List<List<List<Point>>> pitchInfos = new();
1580+
if (Settings.PitchSyncMode)
1581+
{
1582+
foreach (var note in mMoveNotes)
1583+
{
1584+
var pitchInfo = part.Pitch.RangeInfo(note.StartPos(), note.EndPos());
1585+
foreach (var line in pitchInfo)
1586+
{
1587+
for (int i = 0; i < line.Count; i++)
1588+
{
1589+
line[i] = new(line[i].X + note.StartPos() + posOffset, line[i].Y + pitchOffset);
1590+
}
1591+
}
1592+
pitchInfos.Add(pitchInfo);
1593+
}
1594+
}
1595+
15791596
foreach (var note in mMoveNotes)
15801597
{
15811598
note.Pos.Set(note.Pos.Value + posOffset);
15821599
note.Pitch.Set(note.Pitch.Value + pitchOffset);
15831600
part.RemoveNote(note);
15841601
}
1602+
if (Settings.PitchSyncMode)
1603+
{
1604+
foreach (var note in mMoveNotes)
1605+
{
1606+
part.Pitch.Clear(note.StartPos(), note.EndPos());
1607+
}
1608+
}
15851609

15861610
foreach (var note in mMoveNotes)
15871611
{
15881612
part.InsertNote(note);
15891613
}
1614+
if (Settings.PitchSyncMode)
1615+
{
1616+
foreach (var info in pitchInfos)
1617+
{
1618+
foreach (var line in info)
1619+
{
1620+
part.Pitch.AddLine(line, Settings.ParameterBoundaryExtension);
1621+
}
1622+
}
1623+
}
15901624
part.Notes.ListModified.EndMerge();
15911625
part.EndMergeReSegment();
15921626
}

TuneLab/UI/Settings/SettingsWindow.axaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ public SettingsWindow()
216216
}
217217
listView.Content.Children.Add(panel);
218218
}
219+
{
220+
var panel = new DockPanel() { Margin = new(24, 12) };
221+
{
222+
var checkBox = new GUI.Components.CheckBox();
223+
checkBox.Bind(Settings.PitchSyncMode, false, s);
224+
panel.AddDock(checkBox, Dock.Right);
225+
}
226+
{
227+
var name = new TextBlock() { Text = "Pitch Sync Mode: ", VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center };
228+
panel.AddDock(name);
229+
}
230+
listView.Content.Children.Add(panel);
231+
}
219232
{
220233
var panel = new DockPanel() { Margin = new(24, 12) };
221234
{

0 commit comments

Comments
 (0)