Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

功能更新 #103

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions TuneLab/Data/IMidiPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,69 @@ public static void ClearParameters(this IMidiPart part, double start, double end
automation.Clear(start, end, 5);
}
}
internal static MidiPartInfo MergePartInfos(MidiPartInfo[] SortedPartInfos)
{
double PosAxisTrans(PartInfo curPart, double pos)
{
var startPos = SortedPartInfos[0].Pos;
var absPos = pos + curPart.Pos;
return absPos - startPos;
}
var ret = new MidiPartInfo();
var basePart = SortedPartInfos[0];
ret.Pos = SortedPartInfos.First().Pos;
ret.Dur = SortedPartInfos.Last().Dur + SortedPartInfos.Last().Pos - ret.Pos;
ret.Voice = basePart.Voice;
ret.Gain = basePart.Gain;
ret.Name = basePart.Name;
ret.Properties = basePart.Properties;

for (int i = 0; i < SortedPartInfos.Length; i++)
{
var curPart = SortedPartInfos[i];
var curPartPos = PosAxisTrans(curPart, 0);
var nextPartPos = i + 1 < SortedPartInfos.Length ? PosAxisTrans(SortedPartInfos[i + 1], 0) : double.MaxValue;
foreach(var item in curPart.Notes)
{
item.Pos=PosAxisTrans(curPart,item.Pos);
if (item.Pos < curPartPos) continue;
if (item.Pos >= nextPartPos) break;
ret.Notes.Add(item);
}
foreach (var item in curPart.Vibratos)
{
item.Pos = PosAxisTrans(curPart, item.Pos);
if (item.Pos < curPartPos) continue;
if (item.Pos >= nextPartPos) break;
ret.Vibratos.Add(item);
}
foreach (var item in curPart.Pitch)
{
List<Base.Structures.Point> line= new List<Base.Structures.Point>();
foreach (var point in item)
{
var X = PosAxisTrans(curPart, point.X);
if (X < curPartPos) continue;
if (X >= nextPartPos) break;
line.Add(new Base.Structures.Point(X, point.Y));
}
ret.Pitch.Add(line);
}
foreach (var kvp in curPart.Automations)
{
if (!ret.Automations.ContainsKey(kvp.Key)) { ret.Automations.Add(kvp.Key, new AutomationInfo() { DefaultValue = kvp.Value.DefaultValue, Points = new List<Base.Structures.Point>() }); }

foreach (var point in kvp.Value.Points)
{
var X = PosAxisTrans(curPart, point.X);
if (X < curPartPos) continue;
if (X >= nextPartPos) break;
ret.Automations[kvp.Key].Points.Add(new Base.Structures.Point(X, point.Y));
}
}
}
return ret;
}

public static MidiPartInfo RangeInfo(this IMidiPart part, double start, double end)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ protected override void OnMouseDown(MouseDownEventArgs e)
menu.Items.Add(menuItem);
}
}
{
var trackIndex = TrackVerticalAxis.GetPosition(e.Position.Y).TrackIndex;
var track = Project.Tracks[trackIndex];
if (part.IsSelected && track.Parts.Count(p => p.IsSelected) > 1)
{
var partArray = track.Parts.OrderBy(p => p.StartTime).ToArray();
int partIndex = Array.FindIndex(partArray, p => p == part);
int prevIndex = partIndex;
int nextIndex = partIndex;
while (prevIndex > 0) { if (!partArray[prevIndex - 1].IsSelected || partArray[prevIndex - 1] is not MidiPart) break;prevIndex--; }
while (nextIndex < partArray.Length-1) { if (!partArray[nextIndex + 1].IsSelected || partArray[nextIndex+1] is not MidiPart) break; nextIndex++; }
if (nextIndex > prevIndex)
{
var menuItem = new MenuItem().SetName("Merge".Tr(TC.Menu)).SetAction(() =>
{
var oldParts = partArray.Skip(prevIndex).Take(nextIndex - prevIndex + 1);
var oldPartInfos = oldParts.Select(p=>(MidiPartInfo)p.GetInfo()).ToArray();
var newPartInfo = IMidiPartExtension.MergePartInfos(oldPartInfos);
foreach(var oldPart in oldParts) track.RemovePart(oldPart);
track.InsertPart(track.CreatePart(newPartInfo));
track.Commit();
});
menu.Items.Add(menuItem);
}
}
}
{
var menuItem = new MenuItem() { Header = "Set Voice".Tr(TC.Menu) };
var allEngines = VoicesManager.GetAllVoiceEngines();
Expand Down
Loading