Beispiel #1
0
        private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
        {
            ec = e.ColumnIndex;
            if (row >= 0 && sc >= 0 && ec >= sc)
            {
                if (dataGridView1.Rows[row].Cells[e.ColumnIndex].Value == null || dataGridView1.Rows[row].Cells[e.ColumnIndex].Value.ToString() == "")
                {
                    Notes[target].Add(new PianoNote(NoteLib.NoteLib.LUT[dataGridView1.Rows[row].HeaderCell.Value.ToString()], 64, 0, 0, sc, ec, dataGridView1.Rows[row].HeaderCell.Value.ToString(), row));

                    dataGridView1.Rows[row].Cells[sc].Value = dataGridView1.Rows[row].HeaderCell.Value + "*";
                    for (int i = sc + 1; i <= ec; i++)
                    {
                        dataGridView1.Rows[row].Cells[i].Value = "*";
                    }
                }
                else
                {
                    PianoNote n = Notes[target].Find(x => x.freq == NoteLib.NoteLib.LUT[dataGridView1.Rows[row].HeaderCell.Value.ToString()] && x.start <= e.ColumnIndex && x.end >= e.ColumnIndex);
                    for (int i = n.start; i <= n.end; i++)
                    {
                        dataGridView1.Rows[row].Cells[i].Value = "";
                    }
                    Notes[target].Remove(n);
                }
            }
        }
        void LoadMidi(string MidFile, string Track)
        {
            TempoWorker tempo    = new TempoWorker(120, TempoWorker.NoteType.Crotchet);
            MidiRResult MidiRecv = MidiWorker.ReadMidi(MidFile, Track);
            NoteOnEvent FN       = MidiRecv.Notes[0];
            long        off      = FN.AbsoluteTime;

            for (int i = 0; i < MidiRecv.Notes.Count; i++)
            {
                NoteOnEvent NoteEvent = MidiRecv.Notes[i];
                PianoNote   PNote     = new PianoNote(
                    NoteEvent.AbsoluteTime - off,
                    NoteEvent.NoteLength,
                    new BalthasarLib.PianoRollWindow.PitchValuePair((uint)NoteEvent.NoteNumber, 0)
                    );
                PNote.OctaveType = PitchValuePair.OctaveTypeEnum.Piano;
                PNote.Lyric      = PNote.PitchValue.NoteChar + PNote.PitchValue.Octave.ToString();
                NoteList.Add(PNote);
            }
            int j = 0;
            int k = 0;

            PitchList.Add(k, new List <PitchNode>());
            for (int i = 0; i < MidiRecv.Pitchs.Count; i++)
            {
                if (j >= MidiRecv.Notes.Count)
                {
                    break;
                }
                if (MidiRecv.Pitchs[i].PitchWheelChangeEvent.AbsoluteTime - off < NoteList[j].Tick)
                {
                    continue;                                                                                //在音符前,抛弃
                }
                if (MidiRecv.Pitchs[i].PitchWheelChangeEvent.AbsoluteTime - off > NoteList[j].Tick + NoteList[j].Length)
                {
                    //在音符后
                    j++;
                    k++;
                    i--;//重来一遍
                    PitchList.Add(k, new List <PitchNode>());
                    continue;
                }
                PitchValuePair pvp  = new PitchValuePair((uint)MidiRecv.Notes[j].NoteNumber, MidiRecv.Pitchs[i].PIT, (uint)MidiRecv.Pitchs[i].PBS);
                PitchNode      PitN = new PitchNode(MidiRecv.Pitchs[i].PitchWheelChangeEvent.AbsoluteTime - off, pvp.PitchValue);
                PitchList[k].Add(PitN);
            }
        }
        public void clickNoteTop(PianoNote pianoNote, int time, String notePlayed)
        {
            var texture    = font.GetTexture(notePlayed);
            var noteSprite = layer.CreateSprite(texture.Path, OsbOrigin.Centre, pianoNote.getPos() - new Vector2(0, 80));

            noteSprite.Scale(time, 0.18);
            noteSprite.Fade(time, time + 50, 0, 0.66);
            noteSprite.Fade(time + 200, time + 350, 0.66, 0);
            if (notePlayed.Contains('4'))
            {
                noteSprite.ColorHsb(time, time + 350, 0, 1, 1, 0, 1, 1);
            }
            if (notePlayed.Contains('2'))
            {
                noteSprite.ColorHsb(time, time + 350, 120, 1, 1, 120, 1, 1);
            }
            pianoNote.click(time, notePlayed);
        }
        private void pianoRollWindow1_TrackPaint(object sender, BalthasarLib.PianoRollWindow.DrawUtils.TrackDrawUtils utils)
        {
            long mt = pianoRollWindow1.MaxShownTick;
            long nt = pianoRollWindow1.MinShownTick;

            for (int i = 0; i < NoteList.Count; i++)
            {
                PianoNote PN = NoteList[i];
                if (PN.Tick + PN.Length > nt && PN.Tick < mt)
                {
                    utils.DrawNote(PN, Color.SkyBlue);
                }
            }
            foreach (KeyValuePair <int, List <PitchNode> > KV in PitchList)
            {
                utils.DrawPitchLine(KV.Value, Color.Red);
            }
        }
        public override void Generate()
        {
            layer        = GetLayer("Main");
            beatduration = Beatmap.GetTimingPointAt(13).BeatDuration;

            // Loading the big notes

            ArrayList beeg = new ArrayList();

            for (int i = 0; i < 6; i++)
            {
                if (i == 2)
                {
                    continue;
                }
                Vector2 position = new Vector2(320 - 150 + i * 60, 260);
                var     top      = layer.CreateSprite("sb/piano/top.png", OsbOrigin.BottomCentre, position);
                var     bottom   = layer.CreateSprite("sb/piano/bottom.png", OsbOrigin.TopCentre, position + new Vector2(0, 0.1f * 200));
                var     body     = layer.CreateSprite("sb/piano/body.png", OsbOrigin.BottomCentre, position);

                top.Scale(2369, 0.2);
                bottom.Scale(2369, 0.2);
                body.ScaleVec(2369, 0.2, 0.1);
                body.Rotate(2369, Math.PI);

                PianoNote pn1 = new PianoNote(top, bottom, body, position, false, 0.2f);
                pn1.fadeIn(2369);
                pn1.fadeOut(20117);

                beeg.Add(pn1);
            }

            // Loading the small notes

            ArrayList smol = new ArrayList();

            for (int i = 0; i < 7; i++)
            {
                Vector2 position = new Vector2(320 - 180 + i * 60, 220);
                var     top      = layer.CreateSprite("sb/piano/top-fill.png", OsbOrigin.BottomCentre, position - new Vector2(0, 0.075f * 200));
                var     bottom   = layer.CreateSprite("sb/piano/bottom-fill.png", OsbOrigin.TopCentre, position);
                var     body     = layer.CreateSprite("sb/piano/body-fill.png", OsbOrigin.BottomCentre, position);

                top.Scale(2369, 0.15);
                bottom.Scale(2369, 0.15);
                body.ScaleVec(2369, 0.15, 0.075);

                PianoNote pn1 = new PianoNote(top, bottom, body, position, true, 0.15f);
                pn1.fadeIn(2369);
                pn1.fadeOut(20117);

                smol.Add(pn1);
            }


            // Setting font

            font = LoadFont("sb/PianoNotesRegular", new FontDescription()
            {
                FontPath         = "fonts/Altero-Regular.otf",
                FontSize         = 72,
                Color            = Color4.White,
                Padding          = new Vector2(5, 5),
                FontStyle        = FontStyle.Regular,
                TrimTransparency = true,
                EffectsOnly      = false,
                Debug            = false,
            },
                            new FontOutline()
            {
                Thickness = 0,
                Color     = Color.Transparent,
            },
                            new FontShadow()
            {
                Thickness = 0,
                Color     = Color.Transparent,
            });

            Tuple <int, string>[] noteList =
            {
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(3, "A#3"),
                Tuple.Create(0, "C4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(0, "C3"),
                Tuple.Create(1, "D3"),
                Tuple.Create(1, "D#3"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "A#3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "G4"),
                Tuple.Create(0, "C2"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3"),
                Tuple.Create(4, "A#4"),
                Tuple.Create(3, "F3"),
                Tuple.Create(4, "G3")
            };

            double run = StartTime;

            foreach (var note in noteList)
            {
                if (note.Item2.Contains('#'))
                {
                    clickNoteBottom((PianoNote)(beeg[note.Item1]), (int)run, note.Item2);
                }
                else
                {
                    clickNoteTop((PianoNote)(smol[note.Item1]), (int)run, note.Item2);
                }
                run += tick(0, 2);
            }
        }
Beispiel #6
0
        public void DrawNote(PianoNote Note, Color NoteColor, Color LyricColor)
        {
            //判断X相位是否抛弃
            long LeftTick  = Note.Tick;
            long RightTick = Note.Tick + Note.Length;

            long LeftRectangleTick  = pprops.PianoStartTick;
            long RightRectangleTick = pprops.PianoStartTick + (long)Math.Round(pprops.dertPixel2dertTick(baseEvent.ClipRectangle.Width), 0) + 1;

            if (RightTick <= LeftRectangleTick || LeftTick >= RightRectangleTick)
            {
                //抛弃音符(超界)
                return;
            }

            //判断Y相位是否抛弃
            double MaxNoteCount = (double)baseEvent.ClipRectangle.Height / rconf.Const_RollNoteHeight;

            if (MaxNoteCount > (int)MaxNoteCount)
            {
                MaxNoteCount = (int)MaxNoteCount + 1;
            }
            uint MaxNote = pprops.PianoTopNote;
            uint MinNote = MaxNote - (uint)MaxNoteCount;

            if (Note.PitchValue.NoteNumber < MinNote || Note.PitchValue.NoteNumber > MaxNote)
            {
                //抛弃音符(超界)
                return;
            }

            //计算X坐标

            long StartTick   = LeftTick - LeftRectangleTick;  //获得左边界距离启绘点距离;
            long EndTick     = RightTick - LeftRectangleTick; //获得右边界距离启绘点距离;
            int  NoteX1Pixel = baseEvent.ClipRectangle.X;
            int  NoteX2Pixel = NoteX1Pixel;

            if (StartTick < 0)
            {
                //起绘制点小于0;
                NoteX1Pixel = baseEvent.ClipRectangle.X - (int)Math.Round(pprops.dertTick2dertPixel(-StartTick), 0);
                NoteX2Pixel = baseEvent.ClipRectangle.X + (int)Math.Round(pprops.dertTick2dertPixel(EndTick), 0);
            }
            else
            {
                NoteX1Pixel = NoteX1Pixel + (int)Math.Round(pprops.dertTick2dertPixel(StartTick), 0);
                NoteX2Pixel = baseEvent.ClipRectangle.X + (int)Math.Round(pprops.dertTick2dertPixel(EndTick), 0);
            }

            //计算Y坐标
            uint NoteDistance = MaxNote - Note.PitchValue.NoteNumber;
            int  NoteYPixel   = baseEvent.ClipRectangle.Top + (int)NoteDistance * rconf.Const_RollNoteHeight;

            Rectangle NoteRect = new Rectangle(
                new Point(NoteX1Pixel, NoteYPixel),
                new Size(NoteX2Pixel - NoteX1Pixel, rconf.Const_RollNoteHeight)
                );

            Rectangle LyricRect = new Rectangle(
                new Point(NoteX1Pixel + 5, NoteYPixel + 1),
                new Size(NoteX2Pixel - NoteX1Pixel - 5, rconf.Const_RollNoteHeight - 1)
                );

            D2DGraphics g = baseEvent.D2DGraphics;

            g.FillRectangle(NoteRect, NoteColor);
            g.DrawText(Note.Lyric, LyricRect, LyricColor, new System.Drawing.Font("Tahoma", 9));
            g.DrawRectangle(NoteRect, rconf.RollColor_NoteBorderColor);
        }
Beispiel #7
0
 public void DrawNote(PianoNote Note, Color NoteColor)
 {
     DrawNote(Note, NoteColor, Color.Black);
 }
        void PlayMidi(string MidFile, string Track)
        {
            List <PianoNote> NoteListEX = new List <PianoNote>();
            TempoWorker      tempo      = new TempoWorker(120, TempoWorker.NoteType.Crotchet);
            MidiRResult      MidiRecv   = MidiWorker.ReadMidi(MidFile, Track);
            NoteOnEvent      FN         = MidiRecv.Notes[0];
            long             off        = FN.AbsoluteTime;
            long             lastEnd    = 0;

            for (int i = 0; i < MidiRecv.Notes.Count; i++)
            {
                NoteOnEvent NoteEvent = MidiRecv.Notes[i];
                PianoNote   PNote     = new PianoNote(
                    NoteEvent.AbsoluteTime - off,
                    NoteEvent.NoteLength,
                    new BalthasarLib.PianoRollWindow.PitchValuePair((uint)NoteEvent.NoteNumber, 0)
                    );
                PNote.OctaveType = PitchValuePair.OctaveTypeEnum.Piano;
                PNote.Lyric      = PNote.PitchValue.NoteChar + PNote.PitchValue.Octave.ToString();
                if (PNote.Tick > lastEnd)
                {
                    NoteListEX.Add(new PianoNote(lastEnd, PNote.Tick - lastEnd, 0));
                }
                NoteListEX.Add(PNote);
            }
            using (MidiOut midiOut = new MidiOut(0))
            {
                midiOut.Volume = 65535;
                int  j   = 0;
                int  k   = 0;
                bool isp = false;
                for (int i = 0; i < MidiRecv.Pitchs.Count; i++)
                {
                    if (j >= MidiRecv.Notes.Count)
                    {
                        break;
                    }
                    if (MidiRecv.Pitchs[i].PitchWheelChangeEvent.AbsoluteTime - off < 0)
                    {
                        continue;
                    }
                    if (MidiRecv.Pitchs[i].PitchWheelChangeEvent.AbsoluteTime - off < NoteListEX[j].Tick)
                    {
                        System.Threading.Thread.Sleep((int)tempo.Tick2Millisecond(MidiRecv.Pitchs[i].PitchWheelChangeEvent.DeltaTime));
                        continue;    //在音符前,抛弃
                    }
                    if (MidiRecv.Pitchs[i].PitchWheelChangeEvent.AbsoluteTime - off > NoteListEX[j].Tick + NoteListEX[j].Length)
                    {
                        //在音符后
                        midiOut.Send(MidiMessage.StopNote((int)NoteListEX[j].PitchValue.NoteNumber, 0, 1).RawData);
                        isp = false;
                        j++;
                        k++;
                        i--;    //重来一遍
                        PitchList.Add(k, new List <PitchNode>());
                        continue;
                    }
                    if (!isp)
                    {
                        isp = true;
                        midiOut.Send(MidiMessage.StartNote((int)NoteListEX[j].PitchValue.NoteNumber, 127, 1).RawData);
                    }
                    midiOut.Send(MidiRecv.Pitchs[i].PitchWheelChangeEvent.GetAsShortMessage());
                    System.Threading.Thread.Sleep((int)tempo.Tick2Millisecond(MidiRecv.Pitchs[i].PitchWheelChangeEvent.DeltaTime));
                }
            }
        }