Skip to content

Commit

Permalink
Move RemoveSelectedEvents into NoteView.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
paralleltree committed May 8, 2021
1 parent 4c4724c commit a7da4fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
30 changes: 1 addition & 29 deletions Ched/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,35 +610,7 @@ private MenuStrip CreateMainMenu(NoteView noteView)

var flipSelectedNotesItem = new ToolStripMenuItem(MainFormStrings.FlipSelectedNotes, null, (s, e) => noteView.FlipSelectedNotes());
var removeSelectedNotesItem = shortcutItemBuilder.BuildItem(Commands.RemoveSelectedNotes, MainFormStrings.RemoveSelectedNotes);

var removeEventsItem = new ToolStripMenuItem(MainFormStrings.RemoveEvents, null, (s, e) =>
{
int minTick = noteView.SelectedRange.StartTick + (noteView.SelectedRange.Duration < 0 ? noteView.SelectedRange.Duration : 0);
int maxTick = noteView.SelectedRange.StartTick + (noteView.SelectedRange.Duration < 0 ? 0 : noteView.SelectedRange.Duration);
bool isContained(EventBase p) => p.Tick != 0 && minTick <= p.Tick && maxTick >= p.Tick;
var events = ScoreBook.Score.Events;

var bpmOp = events.BpmChangeEvents.Where(p => isContained(p)).ToList().Select(p =>
{
ScoreBook.Score.Events.BpmChangeEvents.Remove(p);
return new RemoveEventOperation<BpmChangeEvent>(events.BpmChangeEvents, p);
}).ToList();

var speedOp = events.HighSpeedChangeEvents.Where(p => isContained(p)).ToList().Select(p =>
{
ScoreBook.Score.Events.HighSpeedChangeEvents.Remove(p);
return new RemoveEventOperation<HighSpeedChangeEvent>(events.HighSpeedChangeEvents, p);
}).ToList();

var signatureOp = events.TimeSignatureChangeEvents.Where(p => isContained(p)).ToList().Select(p =>
{
ScoreBook.Score.Events.TimeSignatureChangeEvents.Remove(p);
return new RemoveEventOperation<TimeSignatureChangeEvent>(events.TimeSignatureChangeEvents, p);
}).ToList();

OperationManager.Push(new CompositeOperation("イベント削除", bpmOp.Cast<IOperation>().Concat(speedOp).Concat(signatureOp)));
noteView.Invalidate();
});
var removeEventsItem = new ToolStripMenuItem(MainFormStrings.RemoveEvents, null, (s, e) => noteView.RemoveSelectedEvents());

var insertAirWithAirActionItem = new ToolStripMenuItem(MainFormStrings.InsertAirWithAirAction, null, (s, e) =>
{
Expand Down
27 changes: 27 additions & 0 deletions Ched/UI/NoteView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using Ched.Core;
using Ched.Core.Notes;
using Ched.Core.Events;
using Ched.Drawing;
using Ched.UI.Operations;

Expand Down Expand Up @@ -2100,6 +2101,32 @@ public void RemoveSelectedNotes()
Invalidate();
}

public void RemoveSelectedEvents()
{
int minTick = SelectedRange.StartTick + (SelectedRange.Duration < 0 ? SelectedRange.Duration : 0);
int maxTick = SelectedRange.StartTick + (SelectedRange.Duration < 0 ? 0 : SelectedRange.Duration);
bool isContained(EventBase p) => p.Tick != 0 && minTick <= p.Tick && maxTick >= p.Tick;
var events = ScoreEvents;

var bpmOp = events.BpmChangeEvents.Where(p => isContained(p)).ToList().Select(p =>
{
return new RemoveEventOperation<BpmChangeEvent>(events.BpmChangeEvents, p);
});

var speedOp = events.HighSpeedChangeEvents.Where(p => isContained(p)).ToList().Select(p =>
{
return new RemoveEventOperation<HighSpeedChangeEvent>(events.HighSpeedChangeEvents, p);
});

var signatureOp = events.TimeSignatureChangeEvents.Where(p => isContained(p)).ToList().Select(p =>
{
return new RemoveEventOperation<TimeSignatureChangeEvent>(events.TimeSignatureChangeEvents, p);
});

OperationManager.InvokeAndPush(new CompositeOperation("イベント削除", bpmOp.Cast<IOperation>().Concat(speedOp).Concat(signatureOp).ToList()));
Invalidate();
}

public void FlipSelectedNotes()
{
var op = FlipNotes(GetSelectedNotes());
Expand Down

0 comments on commit a7da4fb

Please sign in to comment.