コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static Note CreateNote(NoteProperties ni)
        {
            ObjectFactory factory = new ObjectFactory();
            Note          note    = factory.createNote();

            if (ni.chord == true)
            {
                note.setChord(new Empty());
            }


            if (ni.rest == true)
            {
                note.setRest(factory.createRest());
            }
            else
            {
                note.setPitch(CreatePitch(ni.PitchStep, ni.Pitchoctave, ni.PitchAlter));
            }

            //set the duration
            note.setDuration(new BigDecimal(ni.duration));

            //set the tie element
            if (ni.TieType != "")
            {
                note.getTie().add(CreateTie(ni.TieType));
            }


            //Set the Voice
            note.setVoice("1");

            //assign the notetype
            note.setType(CreateNotetype(ni.NoteType));

            //Set a dot
            if (ni.dot == true)
            {
                note.getDot().add(new EmptyPlacement());
            }

            //assign the accidental
            if (ni.AccidentalType != "")
            {
                note.setAccidental(CreateAccidental(ni.AccidentalType));
            }

            //assign the timemodification
            if (ni.TimeModactualnotes != "")
            {
                note.setTimeModification(CreateTimemodification(ni.TimeModactualnotes, ni.TimeModnormalnotes, ni.TimeModnormaltype));
            }

            //Set the note staff
            note.setStaff(new BigInteger(ni.staff.ToString()));

            ////add a beam
            for (int i = 0; i < ni.beamnumber.Count; i++)
            {
                note.getBeam().add(CreateBeam(ni.beamnumber.ElementAt <int>(i), ni.beamvalue.ElementAt <string>(i)));
            }

            if (ni.SlurType != "" | ni.TupletType != "" | ni.TiedType != "" | ni.dynamic != "")
            {
                Notations notations = factory.createNotations();

                //add a tied element
                if (ni.TiedType != "")
                {
                    notations.getTiedOrSlurOrTuplet().add(CreateTied(ni.TiedType));
                }


                //add a slur
                if (ni.SlurType != "")
                {
                    notations.getTiedOrSlurOrTuplet().add(CreateSlur(ni.SlurType));
                }


                //add a tuplet
                if (ni.TupletNumber != 0)
                {
                    notations.getTiedOrSlurOrTuplet().add(CreateTuplet(ni.TupletNumber, ni.TupletType));
                }

                //Adding dynamics here
                if (ni.dynamic != "")
                {
                    Dynamics dynamics = new Dynamics();

                    switch (ni.dynamic)
                    {
                    case "pp":
                    {
                        dynamics.getPOrPpOrPpp().add(factory.createDynamicsPp(new Empty()));
                        //add the dynamic to the direction
                        notations.getTiedOrSlurOrTuplet().add(dynamics);
                        break;
                    }

                    case "p":
                    {
                        dynamics.getPOrPpOrPpp().add(factory.createDynamicsP(new Empty()));
                        //add the dynamic to the direction
                        notations.getTiedOrSlurOrTuplet().add(dynamics);
                        break;
                    }

                    case "mp":
                    {
                        dynamics.getPOrPpOrPpp().add(factory.createDynamicsMp(new Empty()));
                        //add the dynamic to the direction
                        notations.getTiedOrSlurOrTuplet().add(dynamics);
                        break;
                    }

                    case "mf":
                    {
                        dynamics.getPOrPpOrPpp().add(factory.createDynamicsMf(new Empty()));
                        //add the dynamic to the direction
                        notations.getTiedOrSlurOrTuplet().add(dynamics);
                        break;
                    }

                    case "f":
                    {
                        dynamics.getPOrPpOrPpp().add(factory.createDynamicsF(new Empty()));
                        //add the dynamic to the direction
                        notations.getTiedOrSlurOrTuplet().add(dynamics);
                        break;
                    }

                    case "ff":
                    {
                        dynamics.getPOrPpOrPpp().add(factory.createDynamicsFf(new Empty()));
                        //add the dynamic to the direction
                        notations.getTiedOrSlurOrTuplet().add(dynamics);
                        break;
                    }
                    }
                }
                //add the notations to the note
                note.getNotations().add(notations);
            }
            //assign the lyric
            if (ni.LyricText != "")
            {
                note.getLyric().add(CreateLyric(ni.LyricSyllabic, ni.LyricText, ni.LyricEndline));
            }

            return(note);
        }
コード例 #4
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);
        }