Example #1
0
        private Clef clef;                   /** FAB: clef of this staff */

        /** Create a new staff with the given list of music symbols,
         * and the given key signature.  The clef is determined by
         * the clef of the first chord symbol. The track number is used
         * to determine whether to join this left/right vertical sides
         * with the staffs above and below. The SheetMusicOptions are used
         * to check whether to display measure numbers or not.
         */
        public Staff(List <MusicSymbol> symbols, KeySignature key, MidiOptions options, int staffH, int tracknum, int totaltracks)
        {
            keysigWidth      = SheetMusic.KeySignatureWidth(key);
            this.tracknum    = tracknum;
            this.totaltracks = totaltracks;
            this.staffH      = staffH;

            // FAB
            //showMeasures = (options.showMeasures && tracknum == 0);
            showMeasures = options.showMeasures;

            measureLength = options.time.Measure;


            clef = FindClef(symbols);

            clefsym      = new ClefSymbol(clef, 0, false);
            keys         = key.GetSymbols(clef);
            this.symbols = symbols;
            CalculateWidth(options.scrollVert);

            this.Height = CalculateHeight();
            this.Height = staffH;



            CalculateStartEndTime();
            FullJustify();
        }
Example #2
0
 private void cToolStripMenuItem_Click(object sender, EventArgs e)
 {
     viewer.RemoveMusicalSymbol(clef);
     clef = new Clef(ClefType.CClef, 1);
     viewer.InciptInsert(0, clef);
     Display();
 }
Example #3
0
        public void AddElement(IElement aElement)
        {
            if (_isReverse)
            {
                Clef aClef = (Clef)this[0];
                ReverseList();
                Insert(0, aClef);
            }
            else
            {
                if (aElement is Clef)
                {
                    if (this[0] is Clef)
                    {
                        RemoveAt(0);
                    }

                    Insert(0, aElement);
                }
                else
                {
                    Add(aElement);
                }
            }

            _currentIndex = 0;
        }
Example #4
0
        /// <summary>
        /// Returns the top margin value for the ledger line/the space corresponding to the given note.
        /// </summary>
        /// <param name="note"></param>
        /// <param name="octave"></param>
        /// <param name="clef"></param>
        /// <param name="partIndex"></param>
        /// <returns></returns>
        public static double GetNotePos(Note note, Octave octave, Clef clef, byte partIndex)
        {
            double result = GetScoreLinePos(octave, clef, partIndex);

            result -= (byte)note * stepLedgerLine / 2;
            return(result);
        }
Example #5
0
        public static int NumberOfLedgerLines(Note note, Clef clef)
        {
            if (clef == Clef.Bass)
            {
                var ledgerDict = new Dictionary <Note, int>()
                {
                    //bottom
                    { A1, 3 },
                    { B1, 2 },
                    { C1, 2 },
                    { D1, 1 },
                    { E1, 1 },
                    { F1, 0 },

                    //Top
                    { B3, 0 },
                    { C3, 1 },
                    { D3, 1 },
                    { E3, 2 },
                    { F3, 2 },
                    { G3, 3 },
                };

                if (ledgerDict.TryGetValue(note, out var bassCount))
                {
                    return(bassCount);
                }
            }

            if (clef == Clef.Treble)
            {
                var ledgerDict = new Dictionary <Note, int>()
                {
                    //F1, G1, A1, B1, C1, D1, E1,
                    //bottom
                    { F1, 3 },
                    { G1, 2 },
                    { A1, 2 },
                    { B1, 1 },
                    { C1, 1 },
                    { D1, 0 },

                    //Top F3, G3, A3, B3, C3, D3, E3,
                    { F3, 0 },
                    { G3, 0 },
                    { A3, 1 },
                    { B3, 1 },
                    { C3, 2 },
                    { D3, 2 },
                    { E3, 3 },
                };

                if (ledgerDict.TryGetValue(note, out var bassCount))
                {
                    return(bassCount);
                }
            }

            return(0);
        }
Example #6
0
        /// <summary>
        /// Constructor. Creates a new LStaff instance with the specified values.
        /// </summary>
        /// <param name="staff">Required. The Staff instance that this LStaff corresponds to.</param>
        /// <param name="clef">Optional. A clef object to add to the beginning of the staff.</param>
        /// <param name="key">Optional. A Key object to add as a key signature to the beginning of the staff.</param>
        /// <param name="timeSig">Optional. A TimeSignature object to add to the beginning of the staff. This time signature is
        /// applied by deafult to any measures created in the staff.</param>
        /// <param name="measures"></param>
        public LStaff(Staff staff, Clef clef = null, Key key = null, TimeSignature timeSig = null)
        {
            this.staff = staff;
            if (timeSig != null)
            {
                measureDuration = timeSig.WholeNoteCapacity;
            }
            List <MusicalSymbol> symbols = new List <MusicalSymbol>()
            {
                clef, key, timeSig
            };

            if (symbols.Any(e => e != null))
            {
                LMeasure measure = new LMeasure(this, measureDuration);
                foreach (var sym in symbols)
                {
                    if (sym != null)
                    {
                        measure.Add(sym);
                    }
                }
                base.AddLast(measure);
            }
        }
Example #7
0
        private void UpdateMeasureAttributes(MeasureAttributes attributes, List <Staff> staffs, double noteTime)
        {
            //For each staff, refresh timings/clefs etc.
            for (int i = 0; i < staffs.Count; i++)
            {
                Staff staff   = staffs[i];
                Clef  xmlClef = attributes.Clef(i + 1); //xml attrubutes are base 1, not base 0...

                //Check the Clefs not been updated
                if (xmlClef != null && !staff.ClefEquivalentToCurrent(xmlClef))
                {
                    staff.StaffClef.Line = xmlClef.Line;
                    staff.StaffClef.Sign = xmlClef.Sign;
                    staff.AddCleffChange(noteTime);
                }

                Time xmlTime = attributes.Time;
                //Check the timing signature hasn't chagned.
                if (xmlTime != null)
                {
                    if (xmlTime.Beats != staff.Timing.Numerator || xmlTime.Mode != staff.Timing.Denominator)
                    {
                        staff.Timing.Numerator   = xmlTime.Beats;
                        staff.Timing.Denominator = xmlTime.Mode;
                        staff.AddTimingChange(noteTime);
                    }
                }

                Key key = attributes.Key;
                if (key != null)
                {
                    staff.AddKey(noteTime, key);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Returns a standard top value for the ledger line/space used to compute specific top values.
        /// </summary>
        /// <param name="octave"></param>
        /// <param name="clef"></param>
        /// <param name="partIndex"></param>
        /// <returns></returns>
        private static double GetScoreLinePos(Octave octave, Clef clef, byte partIndex)
        {
            double result = scoreOffset;

            if (clef == Clef.treble)
            {
                result = result - stepLedgerLine;

                if (octave == Octave.Octave5)
                {
                }
                else if (octave == Octave.Octave6)
                {
                    result = result - stepLedgerLine * 7 / 2;
                }
                else if (octave == Octave.Octave7)
                {
                    result = result - stepLedgerLine * 14 / 2;
                }
            }
            else if (clef == Clef.bass)
            {
                if (octave == Octave.Octave3)
                {
                }
                else if (octave == Octave.Octave4)
                {
                    result = result - stepLedgerLine * 7 / 2;
                }
            }

            result += lineTopMargin[partIndex];

            return(result);
        }
        public override void ParseElement(MusicXmlParserState state, Staff staff, XElement element)
        {
            ClefType typeOfClef = ClefType.GClef;
            int      line       = 1;

            element.IfElement("sign").HasValue(new Dictionary <string, ClefType> {
                { "G", ClefType.GClef },
                { "C", ClefType.CClef },
                { "F", ClefType.FClef },
                { "percussion", ClefType.Percussion }
            }).Then(v => typeOfClef = v);
            element.IfElement("line").HasValue <int>().Then(v => line = v).Otherwise(s =>
            {
                if (typeOfClef == ClefType.Percussion)
                {
                    line = 2;
                }
            });

            var clef = new Clef(typeOfClef, line);

            element.IfAttribute("number").HasValue <int>().Then(v => clef.Staff = staff.Part.Staves.ElementAt(v - 1));
            element.IfElement("clef-octave-change").HasValue <int>().Then(c => clef.OctaveChange = c);

            var correctStaff = clef.Staff ?? staff;

            correctStaff.Elements.Add(clef);
        }
Example #10
0
        public void ProcessToken(Clef clef)
        {
            var staffClef = new PSAMControlLibrary.Clef(
                ToClefType(clef.Tone), clef.Bar);

            _symbols.Add(staffClef);
        }
 public ScoreService()
 {
     LinePositions = new LineDictionary();
     CurrentClef   = new Clef(ClefType.CClef, 2);
     CurrentKey    = new Key(0);
     CurrentVoice  = 1;
 }
Example #12
0
        private int width; /** Width of symbol */

        #endregion Fields

        #region Constructors

        /**
         * Create a new AccidSymbol with the given accidental, that is
         * displayed at the given note in the given clef.
         */
        public AccidSymbol(Accid accid, WhiteNote note, Clef clef)
        {
            this.accid = accid;
            this.whitenote = note;
            this.clef = clef;
            width = MinWidth;
        }
Example #13
0
        public IEnumerable <MusicalSymbol> ConvertSheet(Sheet sheet)
        {
            var visitor = new Visitor.Visitor();

            List <MusicalSymbol> symbols = new List <MusicalSymbol>();

            var clef = new Clef((ClefType)sheet.Key, 2);

            symbols.Add(clef);
            var timeSignature = new TimeSignature(TimeSignatureType.Numbers, sheet.Bars[0].UpperSignature, sheet.Bars[0].LowerSignature);

            symbols.Add(timeSignature);

            foreach (var bar in sheet.Bars)
            {
                foreach (var note in bar.Notes)
                {
                    note.Visit(visitor);
                    symbols.Add(visitor.Symbol);
                }
                symbols.Add(new Barline());
            }

            return(symbols);
        }
Example #14
0
        /// <summary>
        /// Get a label for a clef
        /// </summary>
        /// <param name="clef">The clef to get the label for</param>
        /// <returns>A label of a clef</returns>
        public static Label RenderClef(Clef clef, double fontSize)
        {
            string symbol;

            switch (clef.sign)
            {
            case ClefSign.G:
                symbol = Constants.Clefs.TREBLE;
                break;

            case ClefSign.C:
                symbol = Constants.Clefs.BASS;
                break;

            //todo: rest of clefs
            default:
                symbol = "";
                break;
            }

            Label clefLabel = WPFRendering.GetMusicalLabel(symbol, fontSize); //todo: get the clef from getmusic label

            clefLabel.VerticalAlignment = VerticalAlignment.Top;
            WPFRendering.RecalculateSize(clefLabel);
            return(clefLabel);
        }
Example #15
0
        private int width;           /** Width of symbol */

        /**
         * Create a new AccidSymbol with the given accidental, that is
         * displayed at the given note in the given clef.
         */
        public AccidSymbol(Accid accid, WhiteNote note, Clef clef)
        {
            this.accid     = accid;
            this.whitenote = note;
            this.clef      = clef;
            width          = MinWidth;
        }
Example #16
0
        public static int DistanceFromMid(Note a, Clef clef)
        {
            var notes = NotesInClef(clef);
            var mid   = Midpoint(clef);

            return(notes.IndexOf(mid) - notes.IndexOf(a));
        }
Example #17
0
        private void ResetMidi()
        {
            // Add sequence
            int numerator   = 4;
            int denominator = 4;

            // BPM de 120
            _division = 960;
            _ppqn     = _division;
            _tempo    = 750000;
            sequence1 = CreateSequence(numerator, denominator, _division, _tempo);

            TimeToTicksConversion = 1000 * ((float)_division / (float)_tempo);

            // Add track
            string        trackName      = "track1";
            string        instrumentName = "AcousticGrandPiano";
            int           channel        = 0;
            int           programChange  = 0;
            int           volume         = 100;
            TimeSignature timesig        = sequence1.Time;
            Clef          clef           = Clef.Treble;

            track1 = CreateTrack(trackName, instrumentName, channel, programChange, volume, _tempo, timesig, clef);

            sequence1.Add(track1);
        }
Example #18
0
 /** Create a new ClefSymbol, with the given clef, starttime, and size */
 public ClefSymbol(Clef clef, int starttime, bool small)
 {
     this.clef = clef;
     this.starttime = starttime;
     smallsize = small;
     LoadImages();
     width = MinWidth;
 }
Example #19
0
        public int DistanceTo(Note note, Clef clef)
        {
            var notes     = Notes.NotesInClef(clef);
            var thisIndex = notes.IndexOf(this);
            var other     = notes.IndexOf(note);

            return(thisIndex - other);
        }
Example #20
0
        public static bool IsOuterLedger(Note note, Clef clef)
        {
            var theNotes = clef == Clef.Bass ? new { low = Notes.E1, high = Notes.C3 } : new { low = Notes.C1, high = Notes.A3 };

            var isLedger = note.RelationTo(theNotes.high, clef) == Relation.Higher || note.RelationTo(theNotes.low, clef) == Relation.Lower;

            return(isLedger);
        }
Example #21
0
 public DataItem(string nameItem, Clef description, int cost, bool saveInInventory, ActionType action)
 {
     this.nameItem        = nameItem;
     this.description     = description;
     this.cost            = cost;
     this.saveInInventory = saveInInventory;
     this.action          = action;
 }
Example #22
0
        public Relation MajorityRelation(Clef clef)
        {
            var relations = Notes.Select(x => x.Note.RelationToMidpoint(clef)).ToList();
            var higher    = relations.Where(x => x == Relation.Higher).ToList().Count;
            var lower     = relations.Where(x => x == Relation.Lower).ToList().Count;

            return(higher > lower ? Relation.Higher : (lower == higher ? Relation.Equal : Relation.Lower));
        }
Example #23
0
 /** Create a new ClefSymbol, with the given clef, starttime, and size */
 public ClefSymbol(Clef clef, int starttime, bool small)
 {
     this.clef      = clef;
     this.starttime = starttime;
     smallsize      = small;
     LoadImages();
     width = MinWidth;
 }
 private static Voice AddBarAndVoiceToTrack(Track track, Clef clef)
 {
     var bar = new Bar();
     bar.Clef = clef;
     track.AddBar(bar);
     var voice = new Voice();
     bar.AddVoice(voice);
     return voice;
 }
Example #25
0
        public ClefViewModel(Clef clef)
        {
            Sections      = new List <NoteSection>();
            NotesInLedger = new ObservableCollection <NoteViewModel>();
            NotesInClef   = new ObservableCollection <NoteViewModel>();
            _createdNotes = new List <NoteViewModel>();

            ActiveClef = clef;
        }
Example #26
0
        private void SetClef(string text)
        {
            Clef tempClef = new Clef
            {
                key = cleffs[text]
            };

            noteBuilder.SetClef(tempClef);
        }
Example #27
0
        private int measure;       /** The length of a measure, in pulses */


        /** Given the notes in a track, calculate the appropriate Clef to use
         * for each measure.  Store the result in the clefs list.
         * @param notes  The midi notes
         * @param measurelen The length of a measure, in pulses
         */
        public ClefMeasures(List <MidiNote> notes, int measurelen)
        {
            measure = measurelen;
            Clef mainclef    = MainClef(notes);
            int  nextmeasure = measurelen;
            int  pos         = 0;
            Clef clef        = mainclef;

            clefs = new List <Clef>();

            while (pos < notes.Count)
            {
                /* Sum all the notes in the current measure */
                int sumnotes  = 0;
                int notecount = 0;
                while (pos < notes.Count && notes[pos].StartTime < nextmeasure)
                {
                    sumnotes += notes[pos].Number;
                    notecount++;
                    pos++;
                }
                if (notecount == 0)
                {
                    notecount = 1;
                }

                /* Calculate the "average" note in the measure */
                int avgnote = sumnotes / notecount;
                if (avgnote == 0)
                {
                    /* This measure doesn't contain any notes.
                     * Keep the previous clef.
                     */
                }
                else if (avgnote >= WhiteNote.BottomTreble.Number())
                {
                    clef = Clef.Treble;
                }
                else if (avgnote <= WhiteNote.TopBass.Number())
                {
                    clef = Clef.Bass;
                }
                else
                {
                    /* The average note is between G3 and F4. We can use either
                     * the treble or bass clef.  Use the "main" clef, the clef
                     * that appears most for this track.
                     */
                    clef = mainclef;
                }

                clefs.Add(clef);
                nextmeasure += measurelen;
            }
            clefs.Add(clef);
        }
Example #28
0
 /** Return the bottom note in the staff of the given clef */
 public static WhiteNote Bottom(Clef clef)
 {
     if (clef == Clef.Treble)
     {
         return(BottomTreble);
     }
     else
     {
         return(BottomBass);
     }
 }
Example #29
0
 /** Return the Accidental symbols for displaying this key signature
  * for the given clef.
  */
 public AccidSymbol[] GetSymbols(Clef clef)
 {
     if (clef == Clef.Treble)
     {
         return(treble);
     }
     else
     {
         return(bass);
     }
 }
Example #30
0
 /** Return the top note in the staff of the given clef */
 public static WhiteNote Top(Clef clef)
 {
     if (clef == Clef.Treble)
     {
         return(TopTreble);
     }
     else
     {
         return(TopBass);
     }
 }
Example #31
0
        public static Note GetInterval(Note n, int interval, Clef clef)
        {
            var source = clef == Clef.Bass ? BassNotes : TrebleNotes;

            source = source.Select(x => x).ToList();             // TODO make a deep copy

            var idx    = source.IndexOf(n);
            var maxIdx = Math.Min(idx + interval, source.Count - 1);

            return(source.ElementAt(maxIdx));
        }
Example #32
0
        private string WriteClef(Clef clef)
        {
            string returnString = "";

            if (clef != currentClef)
            {
                currentClef  = clef;
                returnString = "\\clef " + clefs[clef.key] + "\r\n";
            }
            return(returnString);
        }
Example #33
0
        private static Voice AddBarAndVoiceToTrack(Track track, Clef clef)
        {
            var bar = new Bar();

            bar.Clef = clef;
            track.AddBar(bar);
            var voice = new Voice();

            bar.AddVoice(voice);
            return(voice);
        }
Example #34
0
 private static MusicFontSymbol GetSymbol(Clef clef)
 {
     switch (clef)
     {
         case Clef.Neutral:
             return MusicFontSymbol.ClefNeutral;
         case Clef.C3:
             return MusicFontSymbol.ClefC;
         case Clef.C4:
             return MusicFontSymbol.ClefC;
         case Clef.F4:
             return MusicFontSymbol.ClefF;
         case Clef.G2:
             return MusicFontSymbol.ClefG;
         default:
             return MusicFontSymbol.None;
     }
 }
Example #35
0
		private static Clef GetClef(XmlNode attributesNode)
		{
			var clef = new Clef();

			var clefNode = attributesNode.SelectSingleNode("clef");

			if (clefNode != null)
			{
				var lineNode = clefNode.SelectSingleNode("line");
				if (lineNode != null)
					clef.Line = Convert.ToInt32(lineNode.InnerText);

				var signNode = clefNode.SelectSingleNode("sign");
				if (signNode != null)
					clef.Sign = signNode.InnerText;
			}
			return clef;
		}
Example #36
0
 public ClefGlyph(float x, float y, Clef clef)
     : base(x, y, 1, GetSymbol(clef))
 {
 }
Example #37
0
 /** Return the Accidental symbols for displaying this key signature
  * for the given clef.
  */
 public AccidSymbol[] GetSymbols(Clef clef)
 {
     if (clef == Clef.Treble)
     return treble;
     else
     return bass;
 }
Example #38
0
        private int width; /** The width of the chord */

        #endregion Fields

        #region Constructors

        /** Create a new Chord Symbol from the given list of midi notes.
         * All the midi notes will have the same start time.  Use the
         * key signature to get the white key and accidental symbol for
         * each note.  Use the time signature to calculate the duration
         * of the notes. Use the clef when drawing the chord.
         */
        public ChordSymbol(List<MidiNote> midinotes, KeySignature key, 
            TimeSignature time, Clef c, SheetMusic sheet)
        {
            int len = midinotes.Count;
            int i;

            hastwostems = false;
            clef = c;
            sheetmusic = sheet;

            starttime = midinotes[0].StartTime;
            endtime = midinotes[0].EndTime;

            for (i = 0; i < midinotes.Count; i++) {
            if (i > 1) {
                if (midinotes[i].Number < midinotes[i-1].Number) {
                    throw new System.ArgumentException("Chord notes not in increasing order by number");
                }
            }
            endtime = Math.Max(endtime, midinotes[i].EndTime);
            }

            notedata = CreateNoteData(midinotes, key, time);
            accidsymbols = CreateAccidSymbols(notedata, clef);

            /* Find out how many stems we need (1 or 2) */
            NoteDuration dur1 = notedata[0].duration;
            NoteDuration dur2 = dur1;
            int change = -1;
            for (i = 0; i < notedata.Length; i++) {
            dur2 = notedata[i].duration;
            if (dur1 != dur2) {
                change = i;
                break;
            }
            }

            if (dur1 != dur2) {
            /* We have notes with different durations.  So we will need
             * two stems.  The first stem points down, and contains the
             * bottom note up to the note with the different duration.
             *
             * The second stem points up, and contains the note with the
             * different duration up to the top note.
             */
            hastwostems = true;
            stem1 = new Stem(notedata[0].whitenote,
                             notedata[change-1].whitenote,
                             dur1,
                             Stem.Down,
                             NotesOverlap(notedata, 0, change)
                            );

            stem2 = new Stem(notedata[change].whitenote,
                             notedata[notedata.Length-1].whitenote,
                             dur2,
                             Stem.Up,
                             NotesOverlap(notedata, change, notedata.Length)
                            );
            }
            else {
            /* All notes have the same duration, so we only need one stem. */
            int direction = StemDirection(notedata[0].whitenote,
                                          notedata[notedata.Length-1].whitenote,
                                          clef);

            stem1 = new Stem(notedata[0].whitenote,
                             notedata[notedata.Length-1].whitenote,
                             dur1,
                             direction,
                             NotesOverlap(notedata, 0, notedata.Length)
                            );
            stem2 = null;
            }

            /* For whole notes, no stem is drawn. */
            if (dur1 == NoteDuration.Whole)
            stem1 = null;
            if (dur2 == NoteDuration.Whole)
            stem2 = null;

            width = MinWidth;
        }
Example #39
0
 /** Given the note data (the white keys and accidentals), create
  * the Accidental Symbols and return them.
  */
 private static AccidSymbol[] CreateAccidSymbols(NoteData[] notedata, Clef clef)
 {
     int count = 0;
     foreach (NoteData n in notedata) {
     if (n.accid != Accid.None) {
         count++;
     }
     }
     AccidSymbol[] symbols = new AccidSymbol[count];
     int i = 0;
     foreach (NoteData n in notedata) {
     if (n.accid != Accid.None) {
         symbols[i] = new AccidSymbol(n.accid, n.whitenote, clef);
         i++;
     }
     }
     return symbols;
 }
Example #40
0
        /** Calculate the stem direction (Up or down) based on the top and
         * bottom note in the chord.  If the average of the notes is above
         * the middle of the staff, the direction is down.  Else, the
         * direction is up.
         */
        private static int StemDirection(WhiteNote bottom, WhiteNote top, Clef clef)
        {
            WhiteNote middle;
            if (clef == Clef.Treble)
            middle = new WhiteNote(WhiteNote.B, 5);
            else
            middle = new WhiteNote(WhiteNote.D, 3);

            int dist = middle.Dist(bottom) + middle.Dist(top);
            if (dist >= 0)
            return Stem.Up;
            else
            return Stem.Down;
        }