* Apply R# clean-up for reliability - Migrate to NUnit4 Assert.That - Update dependencise versions - Fix LangVersion to 9.0 (until net core migration) - Reformat code - Apply 'var' style (easier for refactoring) - Remove redundant parentheses - Add braces on every condition blocks (1 line) - Uses new null checking patterns - Uses AutoProperties when possible - Uses string scalar type instead of class - Clean usings - Add .orig files in git ignore - Rename some properties to respect defined conventions and US format definition - ID -> Id - BPM -> Bpm - Finish -> End * Update R# settings according to the clean-up made
125 lines
3.5 KiB
C#
125 lines
3.5 KiB
C#
#region license
|
|
// This file is part of Vocaluxe.
|
|
//
|
|
// Vocaluxe is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Vocaluxe is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
|
|
#endregion
|
|
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace VocaluxeLib.Songs
|
|
{
|
|
public class CSongLine : CLineBase<CSongNote>
|
|
{
|
|
private int _StartBeat = int.MaxValue;
|
|
private int _EndBeat = int.MinValue;
|
|
|
|
#region Constructors
|
|
public CSongLine()
|
|
{
|
|
VisibleInTimeLine = true;
|
|
}
|
|
|
|
public CSongLine(CSongLine line)
|
|
{
|
|
foreach (var note in line._Notes)
|
|
{
|
|
_Notes.Add(new CSongNote(note));
|
|
}
|
|
|
|
_StartBeat = line._StartBeat;
|
|
_EndBeat = line._EndBeat;
|
|
VisibleInTimeLine = line.VisibleInTimeLine;
|
|
}
|
|
#endregion Constructors
|
|
|
|
#region Properties
|
|
public bool VisibleInTimeLine { get; set; }
|
|
|
|
public int StartBeat
|
|
{
|
|
get { return Math.Min(_StartBeat, FirstNoteBeat); }
|
|
set
|
|
{
|
|
if (value <= FirstNoteBeat)
|
|
{
|
|
_StartBeat = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int EndBeat
|
|
{
|
|
get { return Math.Min(_EndBeat, LastNoteBeat); }
|
|
set
|
|
{
|
|
if (value >= LastNoteBeat)
|
|
{
|
|
_EndBeat = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public string Lyrics
|
|
{
|
|
get { return _Notes.Aggregate(string.Empty, (current, note) => current + note.Text); }
|
|
}
|
|
#endregion Properties
|
|
|
|
#region Methods
|
|
public override bool AddNote(CSongNote note)
|
|
{
|
|
if (_Notes.Count == 0)
|
|
{
|
|
_Notes.Add(note);
|
|
}
|
|
else
|
|
{
|
|
//Insert AFTER this note
|
|
var insPos = FindPreviousNote(note.StartBeat);
|
|
//Check for overlapping notes
|
|
if (insPos >= 0) //Check note before
|
|
{
|
|
if (_Notes[insPos].EndBeat >= note.StartBeat)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (insPos < _Notes.Count - 1) //Check note after
|
|
{
|
|
if (_Notes[insPos + 1].StartBeat <= note.EndBeat)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
_Notes.Insert(insPos + 1, note);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void SetMedley(int startBeat, int endBeat)
|
|
{
|
|
foreach (var note in _Notes.Where(note => note.StartBeat < startBeat || note.EndBeat > endBeat))
|
|
{
|
|
note.Type = ENoteType.Freestyle;
|
|
}
|
|
|
|
VisibleInTimeLine = FirstNoteBeat >= startBeat && LastNoteBeat <= endBeat;
|
|
}
|
|
#endregion Methods
|
|
}
|
|
} |