コード例 #1
0
ファイル: InputNoteDef.cs プロジェクト: suvjunmd/Moritz
 private void WriteNoteOnOff(SvgWriter w, TrkOns trkOns, TrkOffs trkOffs)
 {
     if (trkOns != null)
     {
         trkOns.WriteSvg(w);
     }
     if (trkOffs != null)
     {
         trkOffs.WriteSvg(w);
     }
 }
コード例 #2
0
ファイル: InputNoteDef.cs プロジェクト: suvjunmd/Moritz
 /// <summary>
 /// This constructs an InputNoteDef that, when the noteOff arrives, turns off all the trks it has turned on. 
 /// </summary>
 /// <param name="notatedMidiPitch">In range 0..127</param>
 /// <param name="noteOnSeqDefs">Must contain at least one SeqDef</param>
 /// <param name="pressures">Can be null or empty</param>
 /// <param name="inputControls">Can be null</param>
 public InputNoteDef(byte notatedMidiPitch, TrkOns noteOnSeqDef, Pressures pressures, InputControls inputControls)
     : this(notatedMidiPitch, noteOnSeqDef, null, pressures, null, null, inputControls)
 {
     Debug.Assert(noteOnSeqDef != null);
     List<TrkOff> trkOffs = new List<TrkOff>();
     foreach(TrkOn trkOn in NoteOnTrkOns)
     {
         TrkOff trkOff = new TrkOff(trkOn.TrkMidiChannel, trkOn.TrkMsPosition, inputControls);
         trkOffs.Add(trkOff);
     }
     NoteOffTrkOffs = new TrkOffs(trkOffs, null);
 }
コード例 #3
0
ファイル: InputNoteDef.cs プロジェクト: suvjunmd/Moritz
        /// <summary>
        /// This constructs an InputNoteDef that, when the noteOff arrives, turns off all the trks it has turned on.
        /// </summary>
        /// <param name="notatedMidiPitch">In range 0..127</param>
        /// <param name="noteOnSeqDefs">Must contain at least one SeqDef</param>
        /// <param name="pressures">Can be null or empty</param>
        /// <param name="inputControls">Can be null</param>
        public InputNoteDef(byte notatedMidiPitch, TrkOns noteOnSeqDef, Pressures pressures, InputControls inputControls)
            : this(notatedMidiPitch, noteOnSeqDef, null, pressures, null, null, inputControls)
        {
            Debug.Assert(noteOnSeqDef != null);
            List <TrkOff> trkOffs = new List <TrkOff>();

            foreach (TrkOn trkOn in NoteOnTrkOns)
            {
                TrkOff trkOff = new TrkOff(trkOn.TrkMidiChannel, trkOn.TrkMsPosition, inputControls);
                trkOffs.Add(trkOff);
            }
            NoteOffTrkOffs = new TrkOffs(trkOffs, null);
        }
コード例 #4
0
ファイル: InputNoteDef.cs プロジェクト: suvjunmd/Moritz
        /// <summary>
        /// 
        /// </summary>
        /// <param name="notatedMidiPitch">In range 0..127</param>
        /// <param name="noteOnTrkOns">Can be null or empty</param>
        /// <param name="noteOnTrkOffs">Can be null or empty</param>
        /// <param name="pressures">Can be null or empty</param>
        /// <param name="noteOffTrkOns">Can be null or empty</param>
        /// <param name="noteOffTrkOffs">Can be null or empty</param>
        /// <param name="inputControls">Can be null</param>
        public InputNoteDef(byte notatedMidiPitch,
							TrkOns noteOnTrkOns, TrkOffs noteOnTrkOffs,
							Pressures pressures,
							TrkOns noteOffTrkOns, TrkOffs noteOffTrkOffs,
							InputControls inputControls)
        {
            Debug.Assert(notatedMidiPitch >= 0 && notatedMidiPitch <= 127);
            // If inputControls is null, the higher level inputControls are used.

            NotatedMidiPitch = notatedMidiPitch;
            NoteOnTrkOns = noteOnTrkOns;
            NoteOnTrkOffs = noteOnTrkOffs;
            NotePressures = pressures;
            NoteOffTrkOns = noteOffTrkOns;
            NoteOffTrkOffs = noteOffTrkOffs;
            InputControls = inputControls;
        }
コード例 #5
0
ファイル: InputNoteDef.cs プロジェクト: suvjunmd/Moritz
        /// <summary>
        ///
        /// </summary>
        /// <param name="notatedMidiPitch">In range 0..127</param>
        /// <param name="noteOnTrkOns">Can be null or empty</param>
        /// <param name="noteOnTrkOffs">Can be null or empty</param>
        /// <param name="pressures">Can be null or empty</param>
        /// <param name="noteOffTrkOns">Can be null or empty</param>
        /// <param name="noteOffTrkOffs">Can be null or empty</param>
        /// <param name="inputControls">Can be null</param>
        public InputNoteDef(byte notatedMidiPitch,
                            TrkOns noteOnTrkOns, TrkOffs noteOnTrkOffs,
                            Pressures pressures,
                            TrkOns noteOffTrkOns, TrkOffs noteOffTrkOffs,
                            InputControls inputControls)
        {
            Debug.Assert(notatedMidiPitch >= 0 && notatedMidiPitch <= 127);
            // If inputControls is null, the higher level inputControls are used.

            NotatedMidiPitch = notatedMidiPitch;
            NoteOnTrkOns     = noteOnTrkOns;
            NoteOnTrkOffs    = noteOnTrkOffs;
            NotePressures    = pressures;
            NoteOffTrkOns    = noteOffTrkOns;
            NoteOffTrkOffs   = noteOffTrkOffs;
            InputControls    = inputControls;
        }
コード例 #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;
        }
コード例 #7
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;
        }
コード例 #8
0
ファイル: InputNoteDef.cs プロジェクト: suvjunmd/Moritz
 private void WriteNoteOnOff(SvgWriter w, TrkOns trkOns, TrkOffs trkOffs)
 {
     if(trkOns != null)
     {
         trkOns.WriteSvg(w);
     }
     if(trkOffs != null)
     {
         trkOffs.WriteSvg(w);
     }
 }