public void Remove(ScoreNote scoreNote1, ScoreNote scoreNote2) { var tuple = new TupleType(scoreNote1, scoreNote2); var revTuple = new TupleType(scoreNote2, scoreNote1); InternalDictionary.Remove(tuple); InternalDictionary.Remove(revTuple); }
public int RemoveAll(ScoreNote oneOf, NoteRelation relation) { var contained = InternalDictionary.Where(kv => (kv.Key.Item1.Equals(oneOf) || kv.Key.Item2.Equals(oneOf)) && kv.Value == relation).ToArray(); var n = 0; foreach (var kv in contained) { InternalDictionary.Remove(kv.Key); ++n; } return(n); }
private ScoreNote AddScoreNote(ScoreBar scoreBar, int row, int column, Note dataTemplate) { if (row < 0 || column < 0 || column >= 5) { return(null); } var gridCount = scoreBar.Bar.TotalGridCount; if (row >= gridCount) { return(null); } var bar = scoreBar.Bar; var scoreNote = AnyNoteExistOnPosition(bar.Index, column, row); if (scoreNote != null) { return(null); } var barHeight = ScoreBars[0].Height; var baseY = -MinimumScrollOffset + bar.Index * barHeight; var extraY = barHeight * row / bar.TotalGridCount; scoreNote = new ScoreNote(); Note note; if (dataTemplate != null) { note = dataTemplate; } else { note = bar.AddNote(); note.StartPosition = note.FinishPosition = (NotePosition)(column + 1); note.IndexInGrid = row; note.FixSync(); } scoreNote.Note = note; EditableScoreNotes.Add(scoreNote); NoteLayer.Children.Add(scoreNote); scoreNote.X = NoteLayer.ActualWidth * (TrackCenterXPositions[column] - TrackCenterXPositions[0]) / (TrackCenterXPositions[4] - TrackCenterXPositions[0]); scoreNote.Y = baseY + extraY; scoreNote.MouseDown += ScoreNote_MouseDown; scoreNote.MouseUp += ScoreNote_MouseUp; scoreNote.MouseDoubleClick += ScoreNote_MouseDoubleClick; scoreNote.MouseEnter += ScoreNote_MouseEnter; scoreNote.MouseLeave += ScoreNote_MouseLeave; if (dataTemplate == null) { Project.IsChanged = true; } return(scoreNote); }
//private void AssertAllScoreNotesStartAtTheSameTime(ScoreMoment pScoreMoment) //{ // Assert.Greater(pScoreMoment.ScoreNotes.Count, 0); // var firstScoreNote = pScoreMoment.ScoreNotes[0]; // Assert.AreEqual(firstScoreNote.Beat, pScoreMoment.Beat); // Assert.AreEqual(firstScoreNote.Tick, pScoreMoment.Tick); // for (int i = 1; i < pScoreMoment.ScoreNotes.Count; i++) // { // Assert.AreEqual(pScoreMoment.Beat, pScoreMoment.ScoreNotes[i].Beat); // Assert.AreEqual(pScoreMoment.Tick, pScoreMoment.ScoreNotes[i].Tick); // } //} private void AssertScoreNote(ScoreNote pScoreNote, string pNoteId, int pDuration, int pString, int pFret, string pRemarkOrChordName) { Assert.AreEqual(pNoteId, pScoreNote.NoteId); Assert.AreEqual(pDuration, pScoreNote.DurationInTicks); Assert.AreEqual(pRemarkOrChordName, pScoreNote.RemarkOrChordName); if (pScoreNote is GuitarScoreNote) { Assert.AreEqual(pString, ((GuitarScoreNote)pScoreNote).DefaultNotePosition.String); Assert.AreEqual(pFret, ((GuitarScoreNote)pScoreNote).DefaultNotePosition.Fret); } }
private void ScoreBar_MouseUp(object sender, MouseButtonEventArgs e) { var scoreBar = (ScoreBar)sender; var hitTestInfo = scoreBar.HitTest(e.GetPosition(scoreBar)); if (e.ChangedButton == MouseButton.Left) { if (hitTestInfo.IsValid) { var scoreNote = AddScoreNote(scoreBar, hitTestInfo, null); if (scoreNote != null) { var note = scoreNote.Note; if (note.IsSync) { ScoreNote prevScoreNote = null; ScoreNote nextScoreNote = null; if (note.HasPrevSync) { var prevNote = note.PrevSyncTarget; prevScoreNote = FindScoreNote(prevNote); LineLayer.NoteRelations.Add(scoreNote, prevScoreNote, NoteRelation.Sync); } if (note.HasNextSync) { var nextNote = note.NextSyncTarget; nextScoreNote = FindScoreNote(nextNote); LineLayer.NoteRelations.Add(scoreNote, nextScoreNote, NoteRelation.Sync); } if (note.HasPrevSync && note.HasNextSync) { LineLayer.NoteRelations.Remove(prevScoreNote, nextScoreNote); } LineLayer.InvalidateVisual(); } } } else { UnselectAllScoreNotes(); SelectScoreBar(scoreBar); } e.Handled = true; } else { if (HasSelectedScoreNotes) { UnselectAllScoreNotes(); e.Handled = true; } } }
public bool ContainsPair(ScoreNote scoreNote1, ScoreNote scoreNote2) { if (scoreNote1.Equals(scoreNote2)) { return(false); } return(InternalDictionary.Any(kv => { var i1 = kv.Key.Item1; var i2 = kv.Key.Item2; return (i1.Equals(scoreNote1) && i2.Equals(scoreNote2)) || (i1.Equals(scoreNote2) && i2.Equals(scoreNote1)); })); }
public void Test_Huten_16th() { //arr var score = new Score(); var notes = new ScoreNote[] { new ScoreNote() { IsRest = false, Type = ScoreNoteType.eighth, HasDot = true, }, new ScoreNote() { IsRest = true, HasFermata = true, Type = ScoreNoteType.sixteenth, HasDot = false, } }; score.ScoreParts = new List <ScorePart>() { new ScorePart(), new ScorePart() { MeasureList = new Measure[] { new Measure() { Notes = notes } } } }; //do var parser = new GameScoreParser(noteXAdjustment: 0); var gameScore = parser.CreateGameScore(score); //assert var part = gameScore.Parts[0]; { var note = part.Notes[0]; long expectTick = 0; Assert.Equal(expectTick, note.Tick); } { var note = part.Notes[1]; long expectTick = 480 * 3 / 4; Assert.Equal(expectTick, note.Tick); } }
public void GenerateSyncElementForOneScoreNote() { var notes = new SortedList <ScoreNote, ScoreNote>(); var artist = "Metallica"; var title = "For Whom the Bell Tolls"; var xmlScoreWriter = new XmlScoreWriter(artist, title, PlayingMode.EletricGuitarScore, notes); var scoreNote = new ScoreNote("A4", 1, 0, 10, 62250); string xmlScoreNote = "\t<ScoreNote Beat=\"1\" Tick=\"0\" SyncSongPin=\"1:2:250\"/>"; Assert.AreEqual(xmlScoreNote, xmlScoreWriter.GenerateSyncElement(scoreNote)); }
private long GetTicksBase(ScoreNote scoreNote) { switch (scoreNote.Type) { case ScoreNoteType.quarter: return(_tickInTempo); case ScoreNoteType.eighth: return(_tickInTempo / 2); case ScoreNoteType.sixteenth: return(_tickInTempo / 4); default: throw new NotSupportedException($"not supported: {scoreNote.Type}"); } }
private void RemoveScoreNote(ScoreNote scoreNote, bool modifiesModel, bool repositionLines) { if (!ScoreNotes.Contains(scoreNote)) { throw new ArgumentException("Invalid ScoreNote.", nameof(scoreNote)); } scoreNote.MouseDown -= ScoreNote_MouseDown; scoreNote.MouseUp -= ScoreNote_MouseUp; scoreNote.MouseDoubleClick -= ScoreNote_MouseDoubleClick; scoreNote.MouseEnter -= ScoreNote_MouseEnter; scoreNote.MouseLeave -= ScoreNote_MouseLeave; scoreNote.ContextMenu = null; EditableScoreNotes.Remove(scoreNote); LineLayer.NoteRelations.RemoveAll(scoreNote); if (modifiesModel) { var note = scoreNote.Note; if (Score.Bars.Contains(note.Bar)) { // Remove note from sync group // See Note.RemoveSync() if (note.HasPrevSync && note.HasNextSync) { var prevNote = note.PrevSyncTarget; var nextNote = note.NextSyncTarget; var prevScoreNote = FindScoreNote(prevNote); var nextScoreNote = FindScoreNote(nextNote); LineLayer.NoteRelations.Add(prevScoreNote, nextScoreNote, NoteRelation.Sync); } note.RemoveSync(); // The Reset() call is necessary. note.Reset(); note.Bar.RemoveNote(note); } } NoteLayer.Children.Remove(scoreNote); // TODO: Query if there is a need to do that. if (repositionLines) { RepositionLineLayer(); } if (modifiesModel) { Project.IsChanged = true; } }
public string GenerateScoreNoteElement(ScoreNote pScoreNote) { var result = string.Format( "\t<ScoreNote Beat=\"{0}\" Tick=\"{1}\" NoteId=\"{2}\" Duration=\"{3}\"", pScoreNote.Beat, pScoreNote.Tick, pScoreNote.NoteId, pScoreNote.DurationInTicks); if (pScoreNote is GuitarScoreNote) { NotePosition notePosition = ((GuitarScoreNote)pScoreNote).DefaultNotePosition; result += string.Format(" String=\"{0}\" Fret=\"{1}\" RemarkOrChordName=\"{2}\"", notePosition.String, notePosition.Fret, pScoreNote.RemarkOrChordName); } result += "/>"; return(result); }
private void AddNewNote(string pNoteId, long pDeltaTime, byte pVelocity) { fCurrentTime += pDeltaTime; int beat = (int)(fCurrentTime / fBpm) + 1 + fSkipedBeats; long tickTime = fCurrentTime % fBpm; float tickPercent = ((float)tickTime / (float)fBpm); int tick = (int)(tickPercent * 480); if (pVelocity > 0) { var scoreNote = this.NewScoreNote(pNoteId, beat, tick); this.DoAddNewNote((T)scoreNote); } else { try { var noteReference = new MusicalNote(pNoteId); //TODO: refatorar - utilizar FirstOrDefalut e gerar excecao se for nulo (ao inves de um try...catch) ScoreNote note = fScoreNotes.Where(p => (p.Value.DurationInTicks == null) && (p.Value.Note.ToString() == noteReference.ToString())).First().Value; int begin = (note.Beat * ScoreNote.OneBeat) + note.Tick; int end = (beat * ScoreNote.OneBeat) + tick; note.DurationInTicks = end - begin; if (note.DurationInTicks < 0) { throw new InvalidMidiEventsSequence(string.Format("Note {0} on {1}:{2} (beat:tick) with negative duration!", note.NoteId, note.Beat, note.Tick)); } } catch { throw new NoteOnNotFound(string.Format("Invalid event. " + "We found a 0 velocity event but could't find one note {0} with duration null to set.", pNoteId)); } } }
private long GetTicksDot(ScoreNote scoreNote) { if (scoreNote.HasDot == false) { return(0); } switch (scoreNote.Type) { case ScoreNoteType.quarter: return(_tickInTempo / 2); case ScoreNoteType.eighth: return(_tickInTempo / 4); case ScoreNoteType.sixteenth: return(_tickInTempo / 8); default: throw new NotSupportedException($"not supported: {scoreNote.Type}"); } }
public string GenerateSyncElement(ScoreNote pScoreNote) { long momentMin = 0; long momentSec = 0; long momentMilisec = 0; //split the MomentInMiliseconds in Min:Sec:Milisec if (pScoreNote.MomentInMiliseconds != null) { momentMin = pScoreNote.MomentInMiliseconds.Value / 60000; momentSec = (pScoreNote.MomentInMiliseconds.Value - momentMin * 60000) / 1000; momentMilisec = pScoreNote.MomentInMiliseconds.Value % 1000; } var result = string.Format( "\t<ScoreNote Beat=\"{0}\" Tick=\"{1}\" SyncSongPin=\"{4}:{5}:{6}\"", pScoreNote.Beat, pScoreNote.Tick, pScoreNote.NoteId, pScoreNote.DurationInTicks, momentMin, momentSec, momentMilisec); result += "/>"; return(result); }
/// <summary> /// その音が消費するTickを取得します /// </summary> /// <param name="scoreNote"></param> /// <returns></returns> private long GetTicks(ScoreNote scoreNote) { return(GetTicksBase(scoreNote) + GetTicksDot(scoreNote)); }
public void Add(ScoreNote scoreNote1, ScoreNote scoreNote2, NoteRelation relation) { var tuple = new TupleType(scoreNote1, scoreNote2); InternalDictionary.Add(tuple, relation); }
internal Entry(ScoreNote note1, ScoreNote note2, NoteRelation relation) { ScoreNote1 = note1; ScoreNote2 = note2; Relation = relation; }
public void RemoveScoreNote(ScoreNote scoreNote) { RemoveScoreNote(scoreNote, true, true); }
public bool ContainsNote(ScoreNote oneOf) { return(InternalDictionary.Any(kv => kv.Key.Item1.Equals(oneOf) || kv.Key.Item2.Equals(oneOf))); }