94 lines
3.5 KiB
C#
94 lines
3.5 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using JD.Application.Properties;
|
|
using JD.Application.View.Timeline;
|
|
using JD.Audio.Annotations;
|
|
using Signature = JD.Audio.Annotations.Signature;
|
|
|
|
namespace JD.Application.View.Actions
|
|
{
|
|
/// <summary>
|
|
/// Responsible of poping a context menu allowing to manipulate song annotations.
|
|
/// </summary>
|
|
public class TempoBlasterContextMenu : ContextMenuStrip
|
|
{
|
|
private WaveControl _sequencer;
|
|
private Point _dropLocation;
|
|
|
|
public TempoBlasterContextMenu(IContainer components, WaveControl sequencer)
|
|
: base(components)
|
|
{
|
|
_sequencer = sequencer;
|
|
|
|
var songParts = (ToolStripMenuItem)Items.Add("Add Song Part", ResourcesCache.Icons_16x16_Marker);
|
|
foreach (SongSectionType songPartType in SongSectionTypeExtensions.SectionTypes)
|
|
{
|
|
AddMenuItem(songParts, songPartType).BackColor = songPartType.Color();
|
|
}
|
|
Items.Add(songParts);
|
|
|
|
var signatures = (ToolStripMenuItem)Items.Add("Add Signature", ResourcesCache.Icons_16x16_BlueMarker);
|
|
foreach (int beatPerMeasure in Signature.AllowedBeatsPerMeasure)
|
|
{
|
|
AddMenuItem(signatures, beatPerMeasure);
|
|
}
|
|
|
|
Items.Add(signatures);
|
|
|
|
Items.Add(new ToolStripSeparator());
|
|
foreach (CommentType commentType in Enum.GetValues(typeof(CommentType)))
|
|
{
|
|
AddMenuItem(commentType);
|
|
}
|
|
}
|
|
|
|
private void AddMenuItem(CommentType commentType)
|
|
{
|
|
Items.Add(commentType.DisplayName() + " Comment", commentType.Icon()).Click += (s, e) => AddComment(commentType);
|
|
}
|
|
|
|
private ToolStripItem AddMenuItem(ToolStripMenuItem menu, SongSectionType songSectionType)
|
|
{
|
|
menu.DropDownItems.Add(songSectionType.ToString()).Click += (s, e) => AddSongPart(songSectionType);
|
|
return menu.DropDownItems[menu.DropDownItems.Count - 1];
|
|
}
|
|
|
|
private ToolStripItem AddMenuItem(ToolStripMenuItem menu, int beatPerMeasure)
|
|
{
|
|
menu.DropDownItems.Add(Signature.ToString(beatPerMeasure, Signature.Default.NoteValue)).Click += (s, e) => AddSignature(beatPerMeasure);
|
|
return menu.DropDownItems[menu.DropDownItems.Count - 1];
|
|
}
|
|
|
|
private void AddSignature(int beatsPerMeasure)
|
|
{
|
|
_sequencer.Wave.Annotations.Signatures.Add(new Signature(ComputeCreationTime(SnappingUnit.Beat), beatsPerMeasure));
|
|
}
|
|
|
|
private void AddSongPart(SongSectionType type)
|
|
{
|
|
_sequencer.Wave.Annotations.SongSections.Add(new SongSection(type, ComputeCreationTime(SnappingUnit.Measure)));
|
|
}
|
|
|
|
private void AddComment(CommentType type)
|
|
{
|
|
var comment = new Comment(ComputeCreationTime(SnappingUnit.Measure)) {Type = type};
|
|
_sequencer.Wave.Annotations.Comments.Add(comment);
|
|
_sequencer.CommentEditor.EnterEditMode();
|
|
}
|
|
|
|
private BeatUnit ComputeCreationTime(SnappingUnit snapOn)
|
|
{
|
|
BeatUnit beat = _sequencer.Timeline.BeatFromTimeUnit(_sequencer.Timeline.PixelToTime(_dropLocation.X));
|
|
return _sequencer.Timeline.Wave.UnitConverter.Snap(beat, snapOn);
|
|
}
|
|
|
|
protected override void OnOpening(CancelEventArgs e)
|
|
{
|
|
base.OnOpening(e);
|
|
_dropLocation = _sequencer.PointToClient(MousePosition);
|
|
}
|
|
}
|
|
}
|