Пример #1
0
        private void CreateEmptyInputStaves(List <List <VoiceDef> > barDefsInOneSystem)
        {
            int nPrintedOutputStaves = _pageFormat.VisibleOutputVoiceIndicesPerStaff.Count;
            int nPrintedInputStaves  = _pageFormat.VisibleInputVoiceIndicesPerStaff.Count;
            int nStaffNames          = _pageFormat.ShortStaffNames.Count;

            for (int i = 0; i < Systems.Count; i++)
            {
                SvgSystem       system = Systems[i];
                List <VoiceDef> barDef = barDefsInOneSystem[i];

                for (int staffIndex = 0; staffIndex < nPrintedInputStaves; staffIndex++)
                {
                    int    staffNameIndex = nPrintedOutputStaves + staffIndex;
                    string staffname      = StaffName(i, staffNameIndex);

                    float      gap = _pageFormat.Gap * _pageFormat.InputStavesSizeFactor;
                    float      stafflineStemStrokeWidth = _pageFormat.StafflineStemStrokeWidth * _pageFormat.InputStavesSizeFactor;
                    InputStaff inputStaff = new InputStaff(system, staffname, _pageFormat.StafflinesPerStaff[staffIndex], gap, stafflineStemStrokeWidth);

                    List <byte> inputVoiceIndices = _pageFormat.VisibleInputVoiceIndicesPerStaff[staffIndex];
                    for (int ivIndex = 0; ivIndex < inputVoiceIndices.Count; ++ivIndex)
                    {
                        InputVoiceDef inputVoiceDef = barDef[inputVoiceIndices[ivIndex] + _algorithm.MidiChannelIndexPerOutputVoice.Count] as InputVoiceDef;
                        Debug.Assert(inputVoiceDef != null);
                        InputVoice inputVoice = new InputVoice(inputStaff);
                        inputVoice.VoiceDef = inputVoiceDef;
                        inputStaff.Voices.Add(inputVoice);
                    }
                    SetStemDirections(inputStaff);
                    system.Staves.Add(inputStaff);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Returns all the InputChordDefs in the bar.
        /// </summary>
        private List <InputChordDef> GetInputChordDefsInBar(List <VoiceDef> bar)
        {
            List <InputChordDef> inputChordDefs = new List <InputChordDef>();

            foreach (VoiceDef voiceDef in bar)
            {
                InputVoiceDef inputVoiceDef = voiceDef as InputVoiceDef;
                if (inputVoiceDef != null)
                {
                    foreach (IUniqueDef uniqueDef in inputVoiceDef.UniqueDefs)
                    {
                        InputChordDef icd = uniqueDef as InputChordDef;
                        if (icd != null)
                        {
                            inputChordDefs.Add(icd);
                        }
                    }
                }
            }
            return(inputChordDefs);
        }
Пример #3
0
        /// <summary>
        /// There is still one system per bar.
        /// </summary>
        /// <param name="systems"></param>
        public void ConvertVoiceDefsToNoteObjects(List <SvgSystem> systems)
        {
            byte[] currentChannelVelocities = new byte[systems[0].Staves.Count];

            List <ClefChangeDef> voice0ClefChangeDefs = new List <ClefChangeDef>();
            List <ClefChangeDef> voice1ClefChangeDefs = new List <ClefChangeDef>();

            for (int systemIndex = 0; systemIndex < systems.Count; ++systemIndex)
            {
                SvgSystem system            = systems[systemIndex];
                int       visibleStaffIndex = -1;
                for (int staffIndex = 0; staffIndex < system.Staves.Count; ++staffIndex)
                {
                    Staff staff = system.Staves[staffIndex];
                    if (!(staff is InvisibleOutputStaff))
                    {
                        visibleStaffIndex++;
                    }
                    voice0ClefChangeDefs.Clear();
                    voice1ClefChangeDefs.Clear();
                    for (int voiceIndex = 0; voiceIndex < staff.Voices.Count; ++voiceIndex)
                    {
                        Voice voice           = staff.Voices[voiceIndex];
                        float musicFontHeight = (voice is OutputVoice) ? _pageFormat.MusicFontHeight : _pageFormat.MusicFontHeight * _pageFormat.InputStavesSizeFactor;
                        if (!(staff is InvisibleOutputStaff))
                        {
                            Debug.Assert(_pageFormat.ClefsList[visibleStaffIndex] != null);
                            voice.NoteObjects.Add(new ClefSymbol(voice, _pageFormat.ClefsList[visibleStaffIndex], musicFontHeight));
                        }
                        bool firstLmdd = true;

                        if (staff is InputStaff)
                        {
                            InputVoice inputVoice = staff.Voices[voiceIndex] as InputVoice;
                            if (systemIndex == 0)
                            {
                                InputVoiceDef inputVoiceDef = inputVoice.VoiceDef as InputVoiceDef;
                                inputVoice.SetMidiChannel(inputVoiceDef.MidiChannel, systemIndex);
                            }
                        }
                        foreach (IUniqueDef iud in voice.VoiceDef.UniqueDefs)
                        {
                            NoteObject noteObject =
                                SymbolSet.GetNoteObject(voice, iud, firstLmdd, ref currentChannelVelocities[staffIndex], musicFontHeight);

                            ClefChangeSymbol clefChangeSymbol = noteObject as ClefChangeSymbol;
                            if (clefChangeSymbol != null)
                            {
                                if (voiceIndex == 0)
                                {
                                    voice0ClefChangeDefs.Add(iud as ClefChangeDef);
                                }
                                else
                                {
                                    voice1ClefChangeDefs.Add(iud as ClefChangeDef);
                                }
                            }

                            voice.NoteObjects.Add(noteObject);

                            firstLmdd = false;
                        }
                    }

                    if (voice0ClefChangeDefs.Count > 0 || voice1ClefChangeDefs.Count > 0)
                    {
                        // the main clef on this staff in the next system
                        SetNextSystemClefType(staffIndex, voice0ClefChangeDefs, voice1ClefChangeDefs);
                    }

                    if (staff.Voices.Count == 2)
                    {
                        InsertInvisibleClefChangeSymbols(staff.Voices, voice0ClefChangeDefs, voice1ClefChangeDefs);

                        CheckClefTypes(staff.Voices);

                        StandardSymbolSet standardSymbolSet = SymbolSet as StandardSymbolSet;
                        if (standardSymbolSet != null)
                        {
                            standardSymbolSet.ForceNaturalsInSynchronousChords(staff);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Returns two bars. The first is the beginning of the argument bar up to absoluteSplitPos,
        /// The second is the end of the argument bar beginning at absoluteSplitPos.
        /// The final UniqueMidiDurationDef in each voice.UniqueMidiDurationDefs list is converted
        /// to a FinalLMDDInVoice object containing an MsDurationToBarline property.
        /// If a chord or rest overlaps a barline, a LocalizedCautionaryChordDef object is created at the
        /// start of the voice.UniqueMidiDurationDefs in the second bar. A LocalizedCautionaryChordDef
        /// object is a kind of chord which is used while justifying systems, but is not displayed and
        /// does not affect performance.
        /// ClefChangeDefs are placed at the end of the first bar, not at the start of the second bar.
        /// </summary>
        protected List <List <VoiceDef> > SplitBar(List <VoiceDef> originalBar, int absoluteSplitPos)
        {
            List <List <VoiceDef> > twoBars   = new List <List <VoiceDef> >();
            List <VoiceDef>         firstBar  = new List <VoiceDef>();
            List <VoiceDef>         secondBar = new List <VoiceDef>();

            twoBars.Add(firstBar);
            twoBars.Add(secondBar);
            int originalBarStartPos = originalBar[0].UniqueDefs[0].MsPosition;
            int originalBarEndPos   =
                originalBar[0].UniqueDefs[originalBar[0].UniqueDefs.Count - 1].MsPosition +
                originalBar[0].UniqueDefs[originalBar[0].UniqueDefs.Count - 1].MsDuration;

            VoiceDef firstBarVoice;
            VoiceDef secondBarVoice;

            foreach (VoiceDef voice in originalBar)
            {
                TrkDef outputVoice = voice as TrkDef;
                if (outputVoice != null)
                {
                    firstBarVoice = new TrkDef(outputVoice.MidiChannel, new List <IUniqueDef>());
                    firstBar.Add(firstBarVoice);
                    secondBarVoice = new TrkDef(outputVoice.MidiChannel, new List <IUniqueDef>());
                    secondBar.Add(secondBarVoice);
                }
                else
                {
                    firstBarVoice = new InputVoiceDef();
                    firstBar.Add(firstBarVoice);
                    secondBarVoice = new InputVoiceDef();
                    secondBar.Add(secondBarVoice);
                }
                foreach (IUniqueDef iUnique in voice.UniqueDefs)
                {
                    int udMsDuration = iUnique.MsDuration;
                    IUniqueSplittableChordDef uniqueChordDef = iUnique as IUniqueSplittableChordDef;
                    if (uniqueChordDef != null)
                    {
                        udMsDuration = (uniqueChordDef.MsDurationToNextBarline == null) ? iUnique.MsDuration : (int)uniqueChordDef.MsDurationToNextBarline;
                    }

                    int udEndPos = iUnique.MsPosition + udMsDuration;

                    if (iUnique.MsPosition >= absoluteSplitPos)
                    {
                        if (iUnique.MsPosition == absoluteSplitPos && iUnique is ClefChangeDef)
                        {
                            firstBarVoice.UniqueDefs.Add(iUnique);
                        }
                        else
                        {
                            Debug.Assert(udEndPos <= originalBarEndPos);
                            secondBarVoice.UniqueDefs.Add(iUnique);
                        }
                    }
                    else if (udEndPos > absoluteSplitPos)
                    {
                        int durationAfterBarline = udEndPos - absoluteSplitPos;
                        if (iUnique is RestDef)
                        {
                            // This is a rest. Split it.
                            RestDef firstRestHalf = new RestDef(iUnique.MsPosition, absoluteSplitPos - iUnique.MsPosition);
                            firstBarVoice.UniqueDefs.Add(firstRestHalf);

                            RestDef secondRestHalf = new RestDef(absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondRestHalf);
                        }
                        else if (iUnique is CautionaryChordDef)
                        {
                            // This is a cautionary chord. Set the position of the following barline, and
                            // Add an LocalizedCautionaryChordDef at the beginning of the following bar.
                            iUnique.MsDuration = absoluteSplitPos - iUnique.MsPosition;
                            firstBarVoice.UniqueDefs.Add(iUnique);

                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)iUnique, absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                        else
                        {
                            // This is a MidiChordDef or a InputChordDef.
                            // Set the position of the following barline, and add a CautionaryChordDef at the beginning
                            // of the following bar.
                            if (uniqueChordDef != null)
                            {
                                uniqueChordDef.MsDurationToNextBarline = absoluteSplitPos - iUnique.MsPosition;
                            }

                            firstBarVoice.UniqueDefs.Add((IUniqueDef)uniqueChordDef);

                            CautionaryChordDef secondLmdd = new CautionaryChordDef((IUniqueChordDef)uniqueChordDef,
                                                                                   absoluteSplitPos, durationAfterBarline);
                            secondBarVoice.UniqueDefs.Add(secondLmdd);
                        }
                    }
                    else
                    {
                        Debug.Assert(udEndPos <= absoluteSplitPos && iUnique.MsPosition >= originalBarStartPos);
                        firstBarVoice.UniqueDefs.Add(iUnique);
                    }
                }
            }
            return(twoBars);
        }
Пример #5
0
        /// <summary>
        /// This function creates only one bar, but with VoiceDef objects.
        /// </summary>
        List <VoiceDef> CreateBar2(int bar2StartMsPos)
        {
            List <VoiceDef> bar = new List <VoiceDef>();

            byte          channel = 0;
            List <TrkDef> trkDefs = new List <TrkDef>();

            foreach (Palette palette in _palettes)
            {
                bar.Add(new TrkDef(channel, new List <IUniqueDef>()));
                TrkDef trkDef = palette.NewTrkDef(channel);
                trkDef.SetMsDuration(6000);
                trkDefs.Add(trkDef);
                ++channel;
            }

            int msPosition        = bar2StartMsPos;
            int maxBarMsPos       = 0;
            int startMsDifference = 1500;

            for (int i = 0; i < trkDefs.Count; ++i)
            {
                int maxMsPos = WriteVoiceMidiDurationDefsInBar2(bar[i], trkDefs[i], msPosition, bar2StartMsPos);
                maxBarMsPos = maxBarMsPos > maxMsPos ? maxBarMsPos : maxMsPos;
                msPosition += startMsDifference;
            }

            // now add the final rest in the bar
            for (int i = 0; i < trkDefs.Count; ++i)
            {
                int mdsdEndPos = trkDefs[i].EndMsPosition;
                if (maxBarMsPos > mdsdEndPos)
                {
                    RestDef rest2Def = new RestDef(mdsdEndPos, maxBarMsPos - mdsdEndPos);
                    bar[i].UniqueDefs.Add(rest2Def);
                }
            }

            InputVoiceDef inputVoiceDef = new InputVoiceDef(maxBarMsPos - bar2StartMsPos);

            inputVoiceDef.StartMsPosition = bar2StartMsPos;
            int msPos = bar2StartMsPos;

            for (int i = 0; i < bar.Count; ++i)
            {
                TrkOn        trkRef  = new TrkOn((byte)i, msPos, 12, null);
                List <TrkOn> trkRefs = new List <TrkOn>()
                {
                    trkRef
                };
                TrkOns seqDef = new TrkOns(trkRefs, null);

                InputNoteDef inputNoteDef = new InputNoteDef(64, seqDef, null, null);

                List <InputNoteDef> inputNoteDefs = new List <InputNoteDef>()
                {
                    inputNoteDef
                };
                InputChordDef inputChordDef = new InputChordDef(msPos, startMsDifference, inputNoteDefs);
                inputVoiceDef.InsertInRest(inputChordDef);
                msPos += startMsDifference;
            }

            bar.Add(inputVoiceDef);
            return(bar);
        }
Пример #6
0
        List <VoiceDef> CreateBar1()
        {
            List <VoiceDef> bar = new List <VoiceDef>();

            byte channel = 0;

            foreach (Palette palette in _palettes)
            {
                TrkDef trkDef = new TrkDef(channel, new List <IUniqueDef>());
                bar.Add(trkDef);
                WriteVoiceMidiDurationDefs1(trkDef, palette);
                ++channel;
            }

            InputVoiceDef inputVoiceDef     = new InputVoiceDef();
            VoiceDef      bottomOutputVoice = bar[0];

            foreach (IUniqueDef iud in bottomOutputVoice.UniqueDefs)
            {
                MidiChordDef mcd = iud as MidiChordDef;
                RestDef      rd  = iud as RestDef;
                if (mcd != null)
                {
                    List <IUniqueDef> iuds = new List <IUniqueDef>()
                    {
                        (IUniqueDef)mcd
                    };

                    // Note that the msPosition of the trkDef is trkDef.StartMsPosition (= iuds[0].msPosition),
                    // which may be greater than the InputChordDef's msPosition
                    TrkDef trkDef = new TrkDef(bottomOutputVoice.MidiChannel, iuds);

                    // If non-null, arg2 overrides the inputControls attached to the InputNote or InputChord.
                    TrkOn        trkRef  = new TrkOn(trkDef, null);
                    List <TrkOn> trkRefs = new List <TrkOn>()
                    {
                        trkRef
                    };
                    TrkOns trkOns = new TrkOns(trkRefs, null);

                    byte      displayPitch = (byte)(mcd.NotatedMidiPitches[0] + 36);
                    Pressure  pressure     = new Pressure(0, null);
                    Pressures pressures    = new Pressures(new List <Pressure>()
                    {
                        pressure
                    }, null);
                    TrkOff        trkOff         = new TrkOff(trkRef.TrkMidiChannel, mcd.MsPosition, null);
                    List <TrkOff> noteOffTrkOffs = new List <TrkOff>()
                    {
                        trkOff
                    };
                    TrkOffs trkOffs = new TrkOffs(noteOffTrkOffs, null);

                    InputNoteDef inputNoteDef = new InputNoteDef(displayPitch,
                                                                 trkOns, null,
                                                                 pressures,
                                                                 null, trkOffs,
                                                                 null);

                    List <InputNoteDef> inputNoteDefs = new List <InputNoteDef>()
                    {
                        inputNoteDef
                    };

                    // The InputChordDef's msPosition must be <= the msPosition of any of the contained trkRefs
                    InputChordDef icd = new InputChordDef(mcd.MsPosition, mcd.MsDuration, inputNoteDefs);

                    inputVoiceDef.UniqueDefs.Add(icd);
                }
                else if (rd != null)
                {
                    RestDef newRest = new RestDef(rd.MsPosition, rd.MsDuration);
                    inputVoiceDef.UniqueDefs.Add(newRest);
                }
            }

            #region set cascading inputControls on the first InputChordDef  (for testing)
            InputChordDef inputChordDef1 = inputVoiceDef.UniqueDefs[0] as InputChordDef;             // no need to check for null here.

            InputControls chordInputControls = new InputControls();

            chordInputControls.VelocityOption  = VelocityOption.overridden;
            chordInputControls.MinimumVelocity = 19;
            inputChordDef1.InputControls       = chordInputControls;

            InputControls noteInputControls = new InputControls();
            noteInputControls.VelocityOption              = VelocityOption.scaled;
            noteInputControls.MinimumVelocity             = 20;
            inputChordDef1.InputNoteDefs[0].InputControls = noteInputControls;

            #endregion

            bar.Add(inputVoiceDef);

            return(bar);
        }