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

改成全轨道可导入,带Track头 #42

Merged
merged 2 commits into from
Jun 26, 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
83 changes: 39 additions & 44 deletions TuneLab/Views/TrackScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,15 @@ public async void ImportTrack()
return;
}
//SelectOne
var srcProject = new Project(srcProjectInfo);
//
TrackSelector trackSelector = new TrackSelector();
for (int i = 0; i < srcProject.Tracks.Count; i++)
for (int i = 0; i < srcProjectInfo.Tracks.Count; i++)
{
var trackItem = new ListBoxItem()
{
Content = String.Format("Track {0} : {1}", i, srcProject.Tracks[i].Name),
Content = String.Format("Track {0} : {1}", i, srcProjectInfo.Tracks[i].Name),
FontSize = 12,
Tag = srcProject.Tracks[i]
Tag = srcProjectInfo.Tracks[i]
};
trackSelector.TrackList.Items.Add(trackItem);
}
Expand All @@ -620,68 +620,63 @@ public async void ImportTrack()
bool keepTempo = trackSelector.isKeepTempo;
foreach (var selectedTrack in trackSelector.TrackList.SelectedItems)
{
ITrack srcTrack = (ITrack)((ListBoxItem)selectedTrack).Tag;
//Sync
dstProject.NewTrack();
var dstTrack = dstProject.Tracks[dstProject.Tracks.Count - 1];
double SyncTick(double src)
TrackInfo srcTrackInfo = (TrackInfo)((ListBoxItem)selectedTrack).Tag;
List<PartInfo> parts = new List<PartInfo>();
foreach (var partInfo in srcTrackInfo.Parts)
{
return dstProject.TempoManager.GetTick(srcProject.TempoManager.GetTime(src));
}
foreach (var srcPart in srcTrack.Parts)
{
if (srcPart.GetInfo().GetType() != typeof(MidiPartInfo)) continue;
var partInfo = (MidiPartInfo)srcPart.GetInfo();
bool isMidiPart =(partInfo.GetType() == typeof(MidiPartInfo));
if (!keepTempo)
{
//SyncPartTick
//Only declare SyncFunction in Useful
var srcTempoManager = (new Project(new ProjectInfo { Tempos=srcProjectInfo.Tempos })).TempoManager;
double SyncTick(double src)
{
partInfo.Pos = SyncTick(partInfo.Pos);
partInfo.Dur = SyncTick(partInfo.Pos + partInfo.Dur) - partInfo.Pos;
return dstProject.TempoManager.GetTick(srcTempoManager.GetTime(src));
}
//SyncPitchTick
//SyncPartTick
partInfo.Dur = SyncTick(partInfo.Pos + partInfo.Dur);
partInfo.Pos = SyncTick(partInfo.Pos);
partInfo.Dur -= partInfo.Pos;
if (isMidiPart)
{
for (var i = 0; i < partInfo.Pitch.Count; i++)
var midiPartInfo = (MidiPartInfo)partInfo;
//SyncPitchTick
for (var i = 0; i < midiPartInfo.Pitch.Count; i++)
{
for (var j = 0; j < partInfo.Pitch[i].Count; j++)
for (var j = 0; j < midiPartInfo.Pitch[i].Count; j++)
{
partInfo.Pitch[i][j] = new Base.Structures.Point() { X = SyncTick(partInfo.Pitch[i][j].X), Y = partInfo.Pitch[i][j].Y };
midiPartInfo.Pitch[i][j] = new Base.Structures.Point() { X = SyncTick(midiPartInfo.Pitch[i][j].X), Y = midiPartInfo.Pitch[i][j].Y };
}
}
}
//SyncNoteTick
{
for (var i = 0; i < partInfo.Notes.Count; i++)
//SyncNoteTick
for (var i = 0; i < midiPartInfo.Notes.Count; i++)
{
partInfo.Notes[i].Dur = SyncTick(partInfo.Notes[i].Pos + partInfo.Notes[i].Dur);
partInfo.Notes[i].Pos = SyncTick(partInfo.Notes[i].Pos);
partInfo.Notes[i].Dur -= partInfo.Notes[i].Pos;
midiPartInfo.Notes[i].Dur = SyncTick(midiPartInfo.Notes[i].Pos + midiPartInfo.Notes[i].Dur);
midiPartInfo.Notes[i].Pos = SyncTick(midiPartInfo.Notes[i].Pos);
midiPartInfo.Notes[i].Dur -= midiPartInfo.Notes[i].Pos;
}
}
//SyncVib
{
for (var i = 0; i < partInfo.Vibratos.Count; i++)
//SyncVib
for (var i = 0; i < midiPartInfo.Vibratos.Count; i++)
{
partInfo.Vibratos[i].Dur = SyncTick(partInfo.Vibratos[i].Pos + partInfo.Vibratos[i].Dur);
partInfo.Vibratos[i].Pos = SyncTick(partInfo.Vibratos[i].Pos);
partInfo.Vibratos[i].Dur -= partInfo.Vibratos[i].Pos;
midiPartInfo.Vibratos[i].Dur = SyncTick(midiPartInfo.Vibratos[i].Pos + midiPartInfo.Vibratos[i].Dur);
midiPartInfo.Vibratos[i].Pos = SyncTick(midiPartInfo.Vibratos[i].Pos);
midiPartInfo.Vibratos[i].Dur -= midiPartInfo.Vibratos[i].Pos;
}
}
//SyncAutomn
{
var automationKeys = partInfo.Automations.Keys.ToList();
//SyncAutomn
var automationKeys = midiPartInfo.Automations.Keys.ToList();
for (var i = 0; i < automationKeys.Count; i++)
{
for (var j = 0; j < partInfo.Automations[automationKeys[i]].Points.Count; j++)
for (var j = 0; j < midiPartInfo.Automations[automationKeys[i]].Points.Count; j++)
{
partInfo.Automations[automationKeys[i]].Points[j] = new Base.Structures.Point() { X = SyncTick(partInfo.Automations[automationKeys[i]].Points[j].X), Y = partInfo.Automations[automationKeys[i]].Points[j].Y };
midiPartInfo.Automations[automationKeys[i]].Points[j] = new Base.Structures.Point() { X = SyncTick(midiPartInfo.Automations[automationKeys[i]].Points[j].X), Y = midiPartInfo.Automations[automationKeys[i]].Points[j].Y };
}
}
}
}
dstTrack.InsertPart(dstTrack.CreatePart(partInfo));
parts.Add(partInfo);
}
dstTrack.Name.Set(srcTrack.Name.Value);
srcTrackInfo.Parts=parts;
dstProject.AddTrack(srcTrackInfo);
}
dstProject.Commit();
}
Expand Down
1 change: 1 addition & 0 deletions TuneLab/Views/TrackSelector.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using TuneLab.GUI;
using TuneLab.Utils;
using Button = TuneLab.GUI.Components.Button;
using CheckBox = TuneLab.GUI.Components.CheckBox;

namespace TuneLab.Views;
internal partial class TrackSelector : Window
Expand Down
Loading