Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static ScorePartwise EditScorePartwise(ScorePartwise spw, ScoreProperties editedprop)
        {
            ScoreProperties scoreprop = ReadDS.ReadScore(spw);

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

            scoreprop.WorkTitle        = editedprop.WorkTitle == ""?scoreprop.WorkTitle:editedprop.WorkTitle;
            scoreprop.MovementTitle    = editedprop.MovementTitle == "" ? scoreprop.MovementTitle : editedprop.MovementTitle;
            scoreprop.EncodingSoftware = editedprop.EncodingSoftware == "" ? scoreprop.EncodingSoftware : editedprop.EncodingSoftware;
            scoreprop.Creator          = editedprop.Creator == "" ? scoreprop.Creator : editedprop.Creator;
            scoreprop.CreditWords      = editedprop.CreditWords == "" ? scoreprop.CreditWords : editedprop.CreditWords;
            scoreprop.PartDisplayName  = editedprop.PartDisplayName == "" ? scoreprop.PartDisplayName : editedprop.PartDisplayName;
            scoreprop.PartAbbreviation = editedprop.PartAbbreviation == "" ? scoreprop.PartAbbreviation : editedprop.PartAbbreviation;
            scoreprop.ScorePartID      = editedprop.ScorePartID == "" ? scoreprop.ScorePartID : editedprop.ScorePartID;
            scoreprop.InstrumentID     = editedprop.InstrumentID == "" ? scoreprop.InstrumentID : editedprop.InstrumentID;
            scoreprop.InstrumentName   = editedprop.InstrumentName == "" ? scoreprop.InstrumentName : editedprop.InstrumentName;
            scoreprop.MidiChannel      = editedprop.MidiChannel == new Integer(0) ? scoreprop.MidiChannel : editedprop.MidiChannel;
            scoreprop.MidiProgram      = editedprop.MidiProgram == new Integer(0) ? scoreprop.MidiProgram : editedprop.MidiProgram;


            return(CreateDS.CreateScorePartwise(scoreprop));
        }
Ejemplo n.º 4
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);
        }