Exemplo n.º 1
0
        public InputChordSymbol(Voice voice, InputChordDef umcd, int minimumCrotchetDurationMS, float fontSize)
            : base(voice, umcd.MsDuration, umcd.MsPosition, minimumCrotchetDurationMS, fontSize)
        {
            _inputChordDef = umcd;

            _msDurationToNextBarline = umcd.MsDurationToNextBarline;

            SetNoteheadPitches(umcd.NotatedMidiPitches);

            if (umcd.Lyric != null)
            {
                LyricText lyricText = new LyricText(this, umcd.Lyric, FontHeight);
                DrawObjects.Add(lyricText);
            }
        }
Exemplo n.º 2
0
        public override NoteObject GetNoteObject(Voice voice, IUniqueDef iud, bool firstDefInVoice,
                                                 ref byte currentVelocity, float musicFontHeight)
        {
            NoteObject         noteObject         = null;
            CautionaryChordDef cautionaryChordDef = iud as CautionaryChordDef;
            MidiChordDef       midiChordDef       = iud as MidiChordDef;
            InputChordDef      inputChordDef      = iud as InputChordDef;
            RestDef            restDef            = iud as RestDef;
            ClefChangeDef      clefChangeDef      = iud as ClefChangeDef;

            PageFormat pageFormat              = voice.Staff.SVGSystem.Score.PageFormat;
            float      cautionaryFontHeight    = pageFormat.CautionaryNoteheadsFontHeight;
            int        minimumCrotchetDuration = pageFormat.MinimumCrotchetDuration;

            if (cautionaryChordDef != null && firstDefInVoice)
            {
                CautionaryChordSymbol cautionaryChordSymbol = new CautionaryChordSymbol(voice, cautionaryChordDef, cautionaryFontHeight);
                noteObject = cautionaryChordSymbol;
            }
            else if (midiChordDef != null)
            {
                OutputChordSymbol outputChordSymbol = new OutputChordSymbol(voice, midiChordDef, minimumCrotchetDuration, musicFontHeight);

                if (midiChordDef.MidiVelocity != currentVelocity)
                {
                    outputChordSymbol.AddDynamic(midiChordDef.MidiVelocity, currentVelocity);
                    currentVelocity = midiChordDef.MidiVelocity;
                }
                noteObject = outputChordSymbol;
            }
            else if (inputChordDef != null)
            {
                InputChordSymbol inputChordSymbol = new InputChordSymbol(voice, inputChordDef, minimumCrotchetDuration, musicFontHeight);
                noteObject = inputChordSymbol;
            }
            else if (restDef != null)
            {
                RestSymbol restSymbol = new RestSymbol(voice, iud, minimumCrotchetDuration, musicFontHeight);
                noteObject = restSymbol;
            }
            else if (clefChangeDef != null)
            {
                ClefChangeSymbol clefChangeSymbol = new ClefChangeSymbol(voice, clefChangeDef.ClefType, cautionaryFontHeight, ((IUniqueDef)iud).MsPosition);
                noteObject = clefChangeSymbol;
            }

            return(noteObject);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }