예제 #1
0
        public static ScorePartwise.Part.Measure CreateMeasure(string MeasureNumber)
        {
            ObjectFactory factory = new ObjectFactory();

            ScorePartwise.Part.Measure measure = factory.createScorePartwisePartMeasure();
            measure.setNumber(MeasureNumber);
            return(measure);
        }
예제 #2
0
        public static int getNotesperMeasure(ScorePartwise.Part.Measure measure)
        {
            int x = 0;

            for (int i = 0; i < measure.getNoteOrBackupOrForward().size(); i++)
            {
                if (measure.getNoteOrBackupOrForward().get(i) is Note)
                {
                    x++;
                }
            }
            return(x);
        }
예제 #3
0
        public static Attributes EditAttributes(ScorePartwise.Part.Measure measure, AttributeProperties editprop)
        {
            AttributeProperties attprop = ReadDS.ReadAttributes(measure);

            //if the edited properties are other than the default than assign them to the scoreprop

            attprop.fifths          = editprop.fifths == ""? attprop.fifths: editprop.fifths;
            attprop.mode            = editprop.mode == ""? attprop.mode: editprop.mode;
            attprop.BeatsPerMeasure = editprop.BeatsPerMeasure == ""? attprop.BeatsPerMeasure: editprop.BeatsPerMeasure;
            attprop.BeatType        = editprop.BeatType == ""? attprop.BeatType: editprop.BeatType;
            attprop.ClefSign        = editprop.ClefSign == ""? attprop.ClefSign: editprop.ClefSign;
            attprop.ClefLine        = editprop.ClefLine == ""? attprop.ClefLine: editprop.ClefLine;
            attprop.divisions       = editprop.divisions == 0? attprop.divisions: editprop.divisions;
            attprop.staves          = editprop.staves == 1? attprop.staves:editprop.staves;

            return(CreateDS.CreateAttribute(attprop));
        }
예제 #4
0
        public static int getbarindex(int index, ScorePartwise.Part.Measure measure)
        {
            int x = 0;

            for (int i = 0; i < measure.getNoteOrBackupOrForward().size(); i++)
            {
                if (measure.getNoteOrBackupOrForward().get(i) is Barline)
                {
                    x++;
                }
                if (index == x)
                {
                    return(i);
                }
            }
            return(-1);
        }
예제 #5
0
        public static ScorePartwise.Part.Measure EditNote(ScorePartwise.Part.Measure measure, int notenumber, NoteProperties editprop)
        {
            NoteProperties noteprop = ReadDS.ReadNote(notenumber, measure);

            noteprop.PitchStep      = editprop.PitchStep == "" ? noteprop.PitchStep : editprop.PitchStep;
            noteprop.Pitchoctave    = editprop.Pitchoctave == 0? noteprop.Pitchoctave: editprop.Pitchoctave;
            noteprop.NoteType       = editprop.NoteType == "" ? noteprop.NoteType : editprop.NoteType;
            noteprop.LyricSyllabic  = editprop.LyricSyllabic == "" ? noteprop.LyricSyllabic : editprop.LyricSyllabic;
            noteprop.LyricText      = editprop.LyricText == "" ? noteprop.LyricText : editprop.LyricText;
            noteprop.AccidentalType = editprop.AccidentalType == "" ? noteprop.AccidentalType : editprop.AccidentalType;

            noteprop.duration     = editprop.duration == 0 ? noteprop.duration : editprop.duration;
            noteprop.rest         = editprop.rest == null ? noteprop.rest : editprop.rest;
            noteprop.LyricEndline = editprop.LyricEndline == null ? noteprop.LyricEndline : editprop.LyricEndline;
            noteprop.dot          = editprop.dot == null ? noteprop.dot : editprop.dot;
            noteprop.chord        = editprop.chord == null ? noteprop.chord : editprop.chord;
            noteprop.PitchAlter   = editprop.PitchAlter == float.MaxValue ? noteprop.PitchAlter : editprop.PitchAlter;

            //to remove pass -1
            noteprop.TupletNumber       = editprop.TupletNumber == 0 ? noteprop.TupletNumber : (editprop.TupletNumber == -1 ? 0 : editprop.TupletNumber);
            noteprop.TupletType         = editprop.TupletType == "" ? noteprop.TupletType : editprop.TupletType;
            noteprop.dynamic            = editprop.dynamic == "" ? noteprop.dynamic : (editprop.dynamic == "remove" ? "" : editprop.dynamic);
            noteprop.dynamic            = editprop.dynamic == "" ? noteprop.dynamic : editprop.dynamic;
            noteprop.SlurType           = editprop.SlurType == ""? noteprop.SlurType:(editprop.SlurType == "remove" ? "" : editprop.SlurType);
            noteprop.TieType            = editprop.TieType == "" ? noteprop.TieType : (editprop.TieType == "remove" ? "" : editprop.TieType);
            noteprop.TiedType           = editprop.TiedType == "" ? noteprop.TiedType : (editprop.TiedType == "remove" ? "" : editprop.TiedType);
            noteprop.TimeModactualnotes = editprop.TimeModactualnotes == "" ? noteprop.TimeModactualnotes : (editprop.TimeModactualnotes == "remove" ? "" : editprop.TimeModactualnotes);
            noteprop.TimeModnormalnotes = editprop.TimeModnormalnotes == "" ? noteprop.TimeModnormalnotes : (editprop.TimeModnormalnotes == "remove" ? "" : editprop.TimeModnormalnotes);
            noteprop.TimeModnormaltype  = editprop.TimeModnormaltype == "" ? noteprop.TimeModnormaltype : (editprop.TimeModnormaltype == "remove" ? "" : editprop.TimeModnormaltype);



            ///////////////////////////////// Complete Me
            ////Beams cannot Beam removed currently
            noteprop.beamnumber = editprop.beamnumber.Count == 0 ? noteprop.beamnumber : editprop.beamnumber;
            noteprop.beamvalue  = editprop.beamvalue.Count == 0 ? noteprop.beamvalue : editprop.beamvalue;

            measure.getNoteOrBackupOrForward().set(getnoteindex(notenumber, measure), CreateDS.CreateNote(noteprop));

            return(measure);
        }
예제 #6
0
        //Read the attribute
        public static AttributeProperties ReadAttributes(ScorePartwise.Part.Measure measure)
        {
            /* get the attributes Initialization properties */
            for (int i = 0; i < measure.getNoteOrBackupOrForward().size(); i++)
            {
                if (measure.getNoteOrBackupOrForward().get(i) is Attributes)
                {
                    Attributes          attribute = (Attributes)measure.getNoteOrBackupOrForward().get(i);
                    AttributeProperties attprop   = new AttributeProperties();
                    if (attribute.getKey().size() > 0)
                    {
                        Key key = (Key)attribute.getKey().get(0);

                        attprop.fifths = key.getFifths().toString();
                        attprop.mode   = key.getMode();
                    }
                    if (attribute.getClef().size() > 0)
                    {
                        Clef clef = (Clef)attribute.getClef().get(0);
                        attprop.ClefSign = clef.getSign().name();
                        attprop.ClefLine = clef.getLine().toString();
                    }
                    if (attribute.getTime().size() > 0)
                    {
                        Time time = (Time)attribute.getTime().get(0);
                        javax.xml.bind.JAXBElement x = (javax.xml.bind.JAXBElement)time.getTimeSignature().get(0);
                        attprop.BeatsPerMeasure = (string)x.getValue();
                        x = (javax.xml.bind.JAXBElement)time.getTimeSignature().get(1);
                        attprop.BeatType = (string)x.getValue();
                    }
                    if (attribute.getDivisions() is BigDecimal)
                    {
                        attprop.divisions = attribute.getDivisions().intValue();
                    }
                    attprop.staves = attribute.getStaves() is BigInteger?attribute.getStaves().intValue() : 1;

                    return(attprop);
                }
            }
            return(null);
        }
예제 #7
0
 //Read the barline
 public static BarlineProperties ReadBarline(int barnumber, ScorePartwise.Part.Measure measure)
 {
     if (getbarindex(barnumber, measure) != -1)
     {
         Barline           barline = (Barline)measure.getNoteOrBackupOrForward().get(getbarindex(barnumber, measure));
         BarlineProperties barprop = new BarlineProperties();
         if (barline.getEnding() != null)
         {
             barprop.EndingType  = barline.getEnding().getType().value();
             barprop.EndingValue = barline.getEnding().getValue();
         }
         if (barline.getRepeat() != null)
         {
             barprop.RepeatTimes     = barline.getRepeat().getTimes().intValue().ToString();
             barprop.RepeatDirection = barline.getRepeat().getDirection().value();
         }
         barprop.Location = barline.getLocation().value();
         return(barprop);
     }
     return(null);
 }
예제 #8
0
 public static ScorePartwise.Part.Measure DeleteNote(ScorePartwise.Part.Measure measure, int notenumber)
 {
     return((ScorePartwise.Part.Measure)measure.getNoteOrBackupOrForward().remove(getnoteindex(notenumber, measure)));
 }
예제 #9
0
 public static ScorePartwise.Part.Measure deleteBarline(ScorePartwise.Part.Measure measure, int barnumber)
 {
     return((ScorePartwise.Part.Measure)measure.getNoteOrBackupOrForward().remove(getbarindex(barnumber, measure)));
 }
예제 #10
0
        /// <summary>
        /// Checks if the notes are according to the timesignature
        /// </summary>
        /// <param name="scorePartwise"></param>
        /// <returns></returns>
        public static ScorePartwise CheckAndReAlign(ScorePartwise scorePartwise)
        {
            double DivPerMeasure = 16;

            for (int i = 0; i < scorePartwise.getPart().size(); i++)
            {
                //for each part in the score
                ScorePartwise.Part part       = (ScorePartwise.Part)scorePartwise.getPart().get(i);
                Queue <Note>       ExtraNotes = new Queue <Note>();

                for (int j = 0; j < part.getMeasure().size(); j++)
                {
                    //for each measure in a part

                    int DSum = 0;
                    ScorePartwise.Part.Measure measure = (ScorePartwise.Part.Measure)part.getMeasure().get(j);
                    //ScorePartwise.Part.Measure TempMeasure = CreateDS.CreateMeasure(j.ToString());
                    AttributeProperties attprop;
                    //check if timesignature is updated this measure or not
                    if (ReadDS.ReadAttributes(measure) != null)
                    {
                        attprop       = ReadDS.ReadAttributes(measure);
                        DivPerMeasure = (attprop.divisions != 0 & attprop.BeatsPerMeasure != "" & attprop.BeatType != "") ?
                                        int.Parse(attprop.BeatsPerMeasure) * 4 * attprop.divisions / int.Parse(attprop.BeatType) : DivPerMeasure;
                    }

                    //check if there are any notes from the previous measure to be added to this measure
                    //and add them to the start of the current measure
                    int max = ExtraNotes.Count;
                    for (int k = 0; k < max; k++)
                    {
                        measure.getNoteOrBackupOrForward().add(k, ExtraNotes.Dequeue());
                    }

                    //check if the notes do not fit in this measure then remove them from the current measure
                    //System.Windows.MessageBox.Show("Initial Number of notes in the measure: " + EditDS.getNotesperMeasure(measure).ToString());
                    int numNotes       = EditDS.getNotesperMeasure(measure);
                    int thresholdIndex = -1;
                    for (int k = 1; k <= numNotes; k++)
                    {
                        NoteProperties noteprop = ReadDS.ReadNote(k, measure);

                        if (DSum + noteprop.duration > DivPerMeasure)
                        {
                            // if the note is too big to fit a measure
                            if (noteprop.duration > DivPerMeasure)
                            {
                                return(null);
                            }
                            thresholdIndex = k;
                            break;
                        }
                        else
                        {
                            DSum += noteprop.duration;
                        }
                    }
                    if (thresholdIndex != -1)
                    {
                        //first queue the extra notes
                        for (int l = thresholdIndex; l <= numNotes; l++)
                        {
                            ExtraNotes.Enqueue((Note)(measure.getNoteOrBackupOrForward().get(EditDS.getnoteindex(l, measure))));
                        }
                        //then remove from the current measure
                        for (int l = thresholdIndex; l <= numNotes; l++)
                        {
                            measure.getNoteOrBackupOrForward().remove(EditDS.getnoteindex(thresholdIndex, measure));
                        }

                        List <int> RestDurations = new List <int>();
                        int        DivLeft       = (int)DivPerMeasure - DSum; //number of divisions left empty in this measure
                        int        power         = 0;
                        while (DivLeft != 0)
                        {
                            if ((DivLeft & 1) != 0)            //check the leftmost bit
                            {
                                RestDurations.Add(1 << power); //rest durations in powers of two
                            }
                            ++power;
                            DivLeft = DivLeft >> 1;
                        }

                        foreach (int dur in RestDurations)
                        {
                            NoteProperties restprop = new NoteProperties();
                            restprop.rest     = true;
                            restprop.duration = dur;

                            measure.getNoteOrBackupOrForward().add(CreateDS.CreateNote(restprop));
                        }
                    }
                    //set the measure in the part
                    part.getMeasure().set(j, measure);
                }

                //After all the measures in the part are finished and the queue still have notes

                while (ExtraNotes.Count != 0)
                {
                    ScorePartwise.Part.Measure measure = CreateDS.CreateMeasure("2");
                    int DSum = 0;
                    while (DSum < DivPerMeasure)
                    {
                        if (ExtraNotes.Count == 0)
                        {
                            break;
                        }
                        if ((DSum + ((BigDecimal)ExtraNotes.Peek().getDuration()).intValue()) > DivPerMeasure)
                        {
                            break;
                        }
                        else
                        {
                            DSum += ((BigDecimal)ExtraNotes.Peek().getDuration()).intValue();
                            measure.getNoteOrBackupOrForward().add(ExtraNotes.Dequeue());
                        }
                    }
                    part.getMeasure().add(measure);
                }
            }

            return(scorePartwise);
        }
예제 #11
0
        //Read the note
        public static NoteProperties ReadNote(int notenumber, ScorePartwise.Part.Measure measure)
        {
            if (getnoteindex(notenumber, measure) != -1)
            {
                Note           note     = (Note)measure.getNoteOrBackupOrForward().get(getnoteindex(notenumber, measure));
                NoteProperties noteprop = new NoteProperties();

                noteprop.chord = note.getChord() == new Empty() ? true : false;

                if (note.getRest() != null)
                {
                    //MessageBox.Show("Rest Read!");

                    noteprop.rest = true;
                    try
                    {
                        noteprop.NoteType = note.getType().getValue();
                    }
                    catch (System.Exception)
                    {
                        noteprop.NoteType = "";
                    }
                }
                else if (note.getPitch() is Pitch)
                {
                    noteprop.NoteType    = note.getType().getValue();   // get the notetype only if it is not a rest
                    noteprop.PitchStep   = note.getPitch().getStep().value();
                    noteprop.Pitchoctave = note.getPitch().getOctave();
                    if (note.getPitch().getAlter() != null)
                    {
                        noteprop.PitchAlter = note.getPitch().getAlter().floatValue();
                    }
                }

                noteprop.duration = note.getDuration().intValue();

                if (note.getTie().size() != 0)
                {
                    Tie tie = (Tie)note.getTie().get(0);
                    noteprop.TieType = tie.getType().toString();
                }



                noteprop.dot = note.getDot().size() == 0? false:true;

                noteprop.AccidentalType = note.getAccidental() == null? "":note.getAccidental().getValue().value();



                if (note.getTimeModification() != null)
                {
                    noteprop.TimeModactualnotes = note.getTimeModification().getActualNotes().intValue().ToString();
                    noteprop.TimeModnormalnotes = note.getTimeModification().getNormalNotes().intValue().ToString();
                    noteprop.TimeModnormaltype  = note.getTimeModification().getNormalType() == null ? "" : note.getTimeModification().getNormalType();
                }

                ///////////////////////////////////COMPLETE ME
                Beam beam;
                for (int i = 0; i < note.getBeam().size(); i++)
                {
                    beam = (Beam)note.getBeam().get(i);
                    noteprop.beamvalue.Add(beam.getValue().value());
                    noteprop.beamnumber.Add(beam.getNumber());
                }

                if (note.getNotations().size() != 0)
                {
                    Notations notations = (Notations)note.getNotations().get(0);
                    for (int i = 0; i < notations.getTiedOrSlurOrTuplet().size(); i++)
                    {
                        if (notations.getTiedOrSlurOrTuplet().get(i) is Tied)
                        {
                            Tied tied = (Tied)notations.getTiedOrSlurOrTuplet().get(i);
                            //if(tied.getNumber().intValue()==1)
                            noteprop.TiedType = tied.getType().value();
                        }

                        if (notations.getTiedOrSlurOrTuplet().get(i) is Slur)
                        {
                            Slur slur = (Slur)notations.getTiedOrSlurOrTuplet().get(i);
                            if (slur.getNumber() == 1)
                            {
                                noteprop.SlurType = slur.getType().value();
                            }
                        }

                        if (notations.getTiedOrSlurOrTuplet().get(i) is Tuplet)
                        {
                            Tuplet tuplet = (Tuplet)notations.getTiedOrSlurOrTuplet().get(i);
                            noteprop.TupletType = tuplet.getType().value();
                            //noteprop.TupletNumber = tuplet.getNumber().intValue();
                        }
                        if (notations.getTiedOrSlurOrTuplet().get(i) is Dynamics)
                        {
                            Dynamics dynamics            = (Dynamics)notations.getTiedOrSlurOrTuplet().get(i);
                            javax.xml.bind.JAXBElement x = (javax.xml.bind.JAXBElement)dynamics.getPOrPpOrPpp().get(0);
                            noteprop.dynamic = x.getName().ToString();
                        }
                    }
                }

                if (note.getLyric().size() != 0)
                {
                    Lyric lyric = (Lyric)note.getLyric().get(0);
                    for (int i = 0; i < lyric.getElisionAndSyllabicAndText().size(); i++)
                    {
                        if (lyric.getElisionAndSyllabicAndText().get(i) is Syllabic)
                        {
                            Syllabic syllabic = (Syllabic)lyric.getElisionAndSyllabicAndText().get(i);
                            noteprop.LyricSyllabic = syllabic.value();
                        }

                        if (lyric.getElisionAndSyllabicAndText().get(i) is TextElementData)
                        {
                            TextElementData text = (TextElementData)lyric.getElisionAndSyllabicAndText().get(i);
                            noteprop.LyricText = text.getValue();
                        }
                    }
                    noteprop.LyricEndline = lyric.getEndLine() == null?false:true;
                }
                return(noteprop);
            }
            return(null);
        }