public NoteBuilder() { note = new NoteMusicXML() { Items = new object[0] }; }
public RestContainterItem(NoteMusicXML note, int itemIndex, string partId, string measureId, string staffId) { itemCanvas = new Canvas(); noteItem = note; this.itemIndex = itemIndex; this.partId = partId; this.measureId = measureId; this.itemStaff = staffId; customPitch = CheckIfCustomPitchSet(); Draw(CheckIfMeasure()); CalculateMinWidth(); CalculateOptWidth(); }
private void DrawAccidental(NoteMusicXML note, int index, DrawingVisualHost noteVisualHost) { AccidentalMusicXML accidental = note.Accidental; string accidentalSymbol = GetAccidentalSymbolString(accidental.Value); double size = 1.0; double totalAccidentalSize = 0.0; bool hasBracket = accidental.BracketSpecified ? accidental.Bracket == YesNoMusicXML.yes: false; bool hasParentheses = accidental.ParenthesesSpecified ? accidental.Parentheses == YesNoMusicXML.yes: false; if (isSmall) { size = 0.7; } if (accidental.SizeSpecified) { size = accidental.Size == SymbolSizeMusicXML.cue ? 0.7 : accidental.Size == SymbolSizeMusicXML.large ? 1.2 : 1.0; } if (accidental.CautionarySpecified) { hasParentheses = accidental.Cautionary == YesNoMusicXML.yes; //! missing implementation if yes } //! accidental.Editiorial skipped... double accidentalWidth = DrawingMethods.GetTextWidth(accidentalSymbol, TypeFaces.GetMusicFont(), isSmall); double accidentalMargin = layoutStyle.NotesStyle.AccidentalToNoteSpace.TenthsToWPFUnit(); double noteHeadYPosition = pitchedValue[index]; if (hasBracket) { totalAccidentalSize += 2 * DrawingMethods.GetTextWidth(MusicSymbols.AccidentalBracketL, TypeFaces.GetMusicFont(), size); } if (hasParentheses) { totalAccidentalSize += 2 * DrawingMethods.GetTextWidth(MusicSymbols.AccidentalParenthesesL, TypeFaces.GetMusicFont(), size); } if (hasBracket || hasParentheses) { string left = hasBracket ? MusicSymbols.AccidentalBracketL : MusicSymbols.AccidentalParenthesesL; noteVisualHost.AddCharacterGlyph(new Point(0 - (totalAccidentalSize + accidentalWidth + accidentalMargin), noteHeadYPosition), left, isSmall, color); string rigth = hasBracket ? MusicSymbols.AccidentalBracketR : MusicSymbols.AccidentalParenthesesR; noteVisualHost.AddCharacterGlyph(new Point(0 - (totalAccidentalSize / 2 + accidentalWidth + accidentalMargin), noteHeadYPosition), accidentalSymbol, isSmall, color); noteVisualHost.AddCharacterGlyph(new Point(0 - (totalAccidentalSize / 2) - accidentalMargin, noteHeadYPosition), rigth, isSmall, color); SetLeftMargin(totalAccidentalSize + accidentalWidth + accidentalMargin); } else { noteVisualHost.AddCharacterGlyph(new Point(0 - accidentalWidth - accidentalMargin, noteHeadYPosition), accidentalSymbol, isSmall, color); SetLeftMargin(accidentalWidth + accidentalMargin); } }
public void GenerateAttributes(TimeSignatures timeSignatures) { string firsMeasureId = _currentPart.Measure.FirstOrDefault().Number; foreach (var measure in _currentPart.Measure) { var currentTimeSig = timeSignatures.GetTimeSignature(measure.Number); int numerator = currentTimeSig.GetNumerator(); int denominator = currentTimeSig.GetDenominator(); int divisions = GetDivisionsMeasureId(measure.Number); //int maxDuration = (int)((4 / (double)denominator) * (divisions * numerator)); int fractionCursor = 0; for (int i = 0; i < measure.Items.Length; i++) { string typeName = measure.Items[i].GetType().Name; switch (typeName) { case nameof(AttributesMusicXML): if (firsMeasureId == measure.Number && fractionCursor == 0) { AttributesChanged(measure.Items[i] as AttributesMusicXML, fractionCursor, measure.Number, true); } else { AttributesChanged(measure.Items[i] as AttributesMusicXML, fractionCursor, measure.Number); } break; case nameof(BackupMusicXML): BackupMusicXML b = (BackupMusicXML)measure.Items[i]; fractionCursor -= (int)b.Duration; break; case nameof(ForwardMusicXML): ForwardMusicXML f = (ForwardMusicXML)measure.Items[i]; fractionCursor += (int)f.Duration; break; case nameof(NoteMusicXML): NoteMusicXML n = (NoteMusicXML)measure.Items[i]; fractionCursor += n.IsChord() || n.IsGrace() ? 0 : n.GetDuration(); break; } } } GenerateClefPerStaffDictionary(); }
public ChordBuilder AddNote(NoteMusicXML note) { if (note == null) { throw new ArgumentException("ChordBuilder::AddNote Argument value 'note' cannot be null"); } if (note.GetNoteType() == NoteChoiceTypeMusicXML.grace) { throw new ArgumentException("ChordBuilder::AddNote Grace notes currently not supported in chords"); } if (notes.Count > 0) { if (notes[0].GetDuration() != note.GetDuration()) { Console.WriteLine("ChordBuilder::AddNote Added note to chord has different duration than chord main note, duration will be corrected to main note"); note.SetDuration(notes[0].GetDuration()); } } notes.Add(note); return(this); }
public ScorePartwisePartMeasureBuilder AddNote(NoteMusicXML note) { measure.AppendNewItem(note); return(this); }
public static ScorePartwiseMusicXML GetScorePartwise() { var partBuilder = new ScorePartwisePartBuilder(); //--- var measureBuilder = new ScorePartwisePartMeasureBuilder(); measureBuilder.AddBaseAttributes( new MeasureItems.AttributesMusicXML { Divisions = 32, DivisionsSpecified = true, Clef = new List <MeasureItems.Attributes.ClefMusicXML> { new MeasureItems.Attributes.ClefMusicXML { Sign = MeasureItems.Attributes.ClefSignMusicXML.G, Line = "2" } }, Key = new List <MeasureItems.Attributes.KeyMusicXML> { new MeasureItems.Attributes.KeyMusicXML { Items = new object[] { 2.ToString() }, ItemsElementName = new MeasureItems.Attributes.KeyChoiceTypes[] { MeasureItems.Attributes.KeyChoiceTypes.fifths }, Number = "1" } }, Time = new List <MeasureItems.Attributes.TimeMusicXML> { new MeasureItems.Attributes.TimeMusicXML { Number = "1", Items = new object[] { 4.ToString(), 4.ToString() }, ItemsElementName = new MeasureItems.Attributes.TimeChoiceTypeMusicXML[] { MeasureItems.Attributes.TimeChoiceTypeMusicXML.beats, MeasureItems.Attributes.TimeChoiceTypeMusicXML.beattype } } } }); var note1 = new NoteMusicXML { Items = new object[] { new PitchMusicXML { Octave = "4", Step = Helpers.SimpleTypes.StepMusicXML.C }, 128 }, ItemsElementName = new NoteChoiceTypeMusicXML[] { NoteChoiceTypeMusicXML.pitch, NoteChoiceTypeMusicXML.duration }, Voice = "1", Stem = new MeasureItems.NoteItems.StemMusicXML { Value = MeasureItems.NoteItems.StemValueMusicXML.up } }; measureBuilder.AddNote(note1); partBuilder.AddMeasure(measureBuilder.Build()); //=== var r = new Random(); for (int i = 0; i < 32; i++) { var measureBuilder2 = new ScorePartwisePartMeasureBuilder(); for (int j = 0; j < 8; j++) { int randChord = r.Next(5) + 2; ChordBuilder chordBuilder = new ChordBuilder(); for (int k = 0; k < randChord; k++) { var randOctave = 3 + j % (r.Next(3) + 1); var builder = new NoteBuilder(); var step = (Helpers.SimpleTypes.StepMusicXML)r.Next(7); //random step var noteX = builder .SetStem(randOctave > 4 ? MeasureItems.NoteItems.StemValueMusicXML.down : MeasureItems.NoteItems.StemValueMusicXML.up) .SetVoice(1) .SetPitch(step, randOctave) .SetDuration(16) .Build(); chordBuilder.AddNote(noteX); } measureBuilder2.AddChord(chordBuilder.Build()); } partBuilder.AddMeasure(measureBuilder2.Build()); } var scoreBuilder = new ScorePartwiseBuilder(); return(scoreBuilder.AddPart(partBuilder.Build(), "Part 0").Build()); }