95 lines
3.5 KiB
C#
95 lines
3.5 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using JD.Application.View.TrackItems;
|
|
using JD.Audio.Annotations;
|
|
using JD.Kernel.StaticHelpers;
|
|
using TeaBox;
|
|
|
|
namespace JD.Application.View.Tracks
|
|
{
|
|
/// <summary>
|
|
/// A track that allows to manipulate song annotations.
|
|
/// </summary>
|
|
public class AnnotationTrack : WaveTrackBase
|
|
{
|
|
private static readonly int _headerIconWidth = Properties.Resources.icon_sound.Width;
|
|
|
|
/// <summary>
|
|
/// When set, will draw this icon on the begin of the track.
|
|
/// </summary>
|
|
public Image HeaderIcon { get; set; }
|
|
|
|
public AnnotationTrack(AnnotationCollection annotations)
|
|
: base(annotations)
|
|
{
|
|
}
|
|
|
|
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
|
|
{
|
|
base.OnPaintBackground(e);
|
|
|
|
if (HeaderIcon != null && Bounds.Height >= HeaderIcon.Height)
|
|
{
|
|
e.Graphics.DrawImage(HeaderIcon, Bounds.Left, Bounds.Top);
|
|
}
|
|
|
|
var textBounds = Bounds;
|
|
textBounds.X += _headerIconWidth;
|
|
textBounds.Width -= _headerIconWidth;
|
|
|
|
using (var format = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center })
|
|
using (var font = new Font(FontFamily.GenericSansSerif, 14, FontStyle.Regular))
|
|
using (var brush = new SolidBrush(Color.FromArgb(100, 30, 30, 30)))
|
|
{
|
|
e.Graphics.DrawString(Text, font, brush, textBounds, format);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// When requested, the track will add an handle for each signature of the song.
|
|
/// </summary>
|
|
public AnnotationTrack ShowSignatures()
|
|
{
|
|
ShowCollection(Annotations.Signatures, model => new SignatureTrackItem(model, Timeline));
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// When requested, the track will add an handle for each song part of the song.
|
|
/// </summary>
|
|
public AnnotationTrack ShowSongSections()
|
|
{
|
|
ShowCollection(Annotations.SongSections, model => new SongSectionTrackItem(model, Timeline));
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// When requested, the track will add an handle for each comment of the song.
|
|
/// </summary>
|
|
public AnnotationTrack ShowComments()
|
|
{
|
|
ShowCollection(Annotations.Comments, model => new CommentTrackItem(model, Timeline));
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// When requested, the track will add an handle for each comment of the song.
|
|
/// </summary>
|
|
public AnnotationTrack ShowComments(CommentType type)
|
|
{
|
|
ShowCollection(Annotations.Comments, model => new CommentTrackItem(model, Timeline),
|
|
model => model.Type == type);
|
|
return this;
|
|
}
|
|
|
|
private void ShowCollection<TModel, TView>(IAnnotationList<TModel> collection, Converter<TModel, TView> itemCreator, Predicate<TModel> includeModel = null)
|
|
where TModel : EditableAnnotation
|
|
where TView : AnnotationTrackItem
|
|
{
|
|
Throw.InvalidOperationIf(Annotations == null, "Assign the annotations first", "Annotations");
|
|
|
|
// Dont need to keep it in another list since it listens to the collection, it will be destroyed on the closing of the wave.
|
|
new TrackItemSynchronizer<TModel, TView>(this, collection, itemCreator, includeModel);
|
|
}
|
|
}
|
|
}
|