Beispiel #1
0
 public Form1(String Path = "", double Speed = 1.00, String image = "", Color?c1 = null, Color?c2 = null, Color?c3 = null, Color?c4 = null, bool RainbowMode = false)
 {
     if (Path != "")
     {
         track     = (Path.Substring(Path.LastIndexOf("\\") + 1, Path.LastIndexOf(".") - Path.LastIndexOf("\\") - 1));
         My        = new MIDINotesData(MIDIFuncs.UnpackDataToNote(Path));
         pathcheck = true;
         ft        = (int)My.flowkeys[0].time;
         st        = (int)My.flowkeys[My.flowkeys.Count - 1].time + (int)My.flowkeys[My.flowkeys.Count - 1].length;
     }
     if (RainbowMode)
     {
         rainbow = new Rainbow();
     }
     red        = new System.Drawing.SolidBrush(c1 ?? Color.Red);
     green      = new System.Drawing.SolidBrush(c2 ?? Color.Green);
     pink       = new System.Drawing.SolidBrush(c3 ?? Color.Pink);
     lightgreen = new System.Drawing.SolidBrush(c4 ?? Color.LightGreen);
     cl1        = c1 ?? Color.Red;
     cl2        = c2 ?? Color.Green;
     cl3        = c3 ?? Color.Pink;
     cl4        = c4 ?? Color.LightGreen;
     Myspeed    = Speed;
     if (image != null)
     {
         //this.BackgroundImage = Image.FromFile(image);
         try
         {
             im = Image.FromFile(image);
         }
         catch (Exception ex)
         { }
     }
     InitializeComponent();
 }
Beispiel #2
0
 //Записывает данные из структуры для хранения информации для падающих клавиш в текстовый файл
 static void midiRawToTXT(MIDINotesData rawData, string path)
 {
     using (var fl = new StreamWriter(path))
     {
         foreach (var flowdata in rawData.flowkeys)
         {
             fl.WriteLine($"{flowdata.pos} {flowdata.time} {flowdata.length}");
         }
     }
 }
Beispiel #3
0
 //Запаковывает информацию для падающих клавиш в файл
 public static void SaveToData(MIDINotesData rawData, string path)
 {
     using (var fl = new BinaryWriter(File.Create(path + ".dat"), Encoding.Default))
     {
         fl.Write(rawData.count);
         foreach (var data in rawData.flowkeys)
         {
             fl.Write(data.pos);
             fl.Write(data.time);
             fl.Write(data.length);
         }
     }
 }
Beispiel #4
0
 public Play(String Path = "")
 {
     if (Path != "")
     {
         My        = new MIDINotesData(MIDIFuncs.UnpackDataToNote(Path));
         pathcheck = true;
         if ((int)My.flowkeys[0].time > 1000)
         {
             time = (int)My.flowkeys[0].time - 1000;
         }
     }
     InitializeComponent();
 }
Beispiel #5
0
 private void PlayLabel_Click(object sender, EventArgs e)
 {
     if (selectedFileName == "")
     {
         return;
     }
     else
     {
         //Player
         My = new MIDINotesData((MIDIFuncs.UnpackDataToNote(libPath + @"\" + selectedFileName + ".dat")));
         if (playing)
         {
             timer1.Stop();
             playLabel.BackgroundImage = Properties.Resources.icons8_play_96_1;
             playing = !playing;
         }
         else
         {
             timer1.Start();
             playLabel.BackgroundImage = Properties.Resources.icons8_pause_96_1;
             playing = !playing;
         }
     }
 }
Beispiel #6
0
        private void MakeRectangle(MIDINotesData M, List <MyRectangle> RectangleList, int Button_Y_Position, int Button_width, double speed)
        {
            //Loop For Making Rectangles
            foreach (var x in M.flowkeys)
            {
                //System.Drawing.SolidBrush r_color = rainbow == null ? red :new System.Drawing.SolidBrush(rainbow.GetNext());
                //System.Drawing.SolidBrush l_color = rainbow == null ? pink : new System.Drawing.SolidBrush(rainbow.GetNext());
                if ((int)((x.time / (timer1.Interval * speed))) == time)
                {
                    if (WhiteKey.Contains(x.pos))      //Check if Button is White
                    {
                        Rectangle R = new Rectangle(); //Creating Rectangle
                        if (x.pos == 1)                //First Button
                        {
                            R.Width = Button_width - 4;
                            R.X     = 0;
                        }
                        else if (x.pos == 88)//Last Button
                        {
                            R.Width = Button_width;
                            R.X     = 1020;
                        }
                        else
                        {
                            //Determine width and place of falling note
                            if (RightBlackKey.Contains(x.pos - 1))
                            {
                                R.X     = ((WhiteKey.IndexOf(x.pos)) * Button_width) + 8;
                                R.Width = Button_width - 8;
                            }
                            else if (LeftBlackKey.Contains(x.pos - 1) && RightBlackKey.Contains(x.pos + 1))
                            {
                                R.X     = ((WhiteKey.IndexOf(x.pos)) * Button_width) + 4;
                                R.Width = Button_width - 8;
                            }
                            else if (LeftBlackKey.Contains(x.pos - 1) && MiddleBlackKey.Contains(x.pos + 1))
                            {
                                R.X     = ((WhiteKey.IndexOf(x.pos)) * Button_width) + 4;
                                R.Width = Button_width - 10;
                            }
                            else if (MiddleBlackKey.Contains(x.pos - 1))
                            {
                                R.X     = ((WhiteKey.IndexOf(x.pos)) * Button_width) + 6;
                                R.Width = Button_width - 10;
                            }
                            else
                            {
                                R.X     = WhiteKey.IndexOf(x.pos) * Button_width;
                                R.Width = Button_width - 9;
                            }
                        }
                        R.Y      = 0;
                        R.Height = 0;
                        if (x.pos <= 44)//button is in the first half
                        {
                            if (x.length > 0)
                            {
                                MyRectangle Rec = new MyRectangle(R, x.length, red, x.pos);
                                RectangleList.Add(Rec);
                            }
                        }
                        else //button is in the second half
                        {
                            if (x.length > 0)
                            {
                                MyRectangle Rec = new MyRectangle(R, x.length, red, x.pos);
                                RectangleList.Add(Rec);
                            }
                        }
                    }
                    else if (!WhiteKey.Contains(x.pos))//Button is black
                    {
                        Rectangle R = new Rectangle();
                        R.Y = 0;
                        //Determine the place of falling note
                        if (RightBlackKey.Contains(x.pos))
                        {
                            R.X = ((WhiteKey.IndexOf(x.pos - 1)) * Button_width) + 16;
                        }
                        else if (LeftBlackKey.Contains(x.pos))
                        {
                            R.X = ((WhiteKey.IndexOf(x.pos - 1)) * Button_width) + 12;
                        }
                        else
                        {
                            R.X = ((WhiteKey.IndexOf(x.pos - 1)) * Button_width) + 14;
                        }

                        R.Width  = Button_width - 8;
                        R.Height = 0;
                        if (x.pos < 44)//button is in the first half
                        {
                            if (x.length > 0)
                            {
                                MyRectangle Rec = new MyRectangle(R, x.length, pink, x.pos);
                                RectangleList.Add(Rec);
                            }
                        }
                        else //button is in the second half
                        {
                            if (x.length > 0)
                            {
                                MyRectangle Rec = new MyRectangle(R, x.length, pink, x.pos);
                                RectangleList.Add(Rec);
                            }
                        }
                    }
                }
            }
            //Loop For Moving Rectangles and play notes
            for (var i = 0; i < RectangleList.Count; i++)
            {
                if (RectangleList[i].Period / 5 >= Button_Y_Position)
                {
                    if (RectangleList[i].MyRec.Height < (RectangleList[i].Period / 5) && RectangleList[i].HeightLeft > 0)
                    {
                        RectangleList[i].increasespeed((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                        if (RectangleList[i].MyRec.Height < Button_Y_Position)
                        {
                            RectangleList[i].IncreaseHeight((int)RectangleList[i].Speed);
                        }
                        RectangleList[i].decreaseHeightLeft((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                    }
                    else
                    {
                        RectangleList[i].Check = true;
                    }
                    if (RectangleList[i].MyRec.Height + RectangleList[i].MyRec.Y >= Button_Y_Position && RectangleList[i].Hit == false)
                    {
                        outDevice.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, RectangleList[i].Position + 20, 127));//playing note
                        if (!play)
                        {
                            play = true;
                        }
                        //change the color of button
                        if (WhiteKey.Contains(RectangleList[i].Position))
                        {
                            if (RectangleList[i].Position <= 44)
                            {
                                buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                            }
                            else
                            {
                                buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                            }
                        }
                        else
                        {
                            if (RectangleList[i].Position <= 44)
                            {
                                buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                            }
                            else
                            {
                                buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                            }
                        }
                        RectangleList[i].Hit = true;
                    }
                    if (RectangleList[i].Hit == true && RectangleList[i].MyRec.Height > 0)
                    {
                        if (RectangleList[i].Check == true)
                        {
                            RectangleList[i].decreaseheight((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                            RectangleList[i].Decrease((int)RectangleList[i].Height);
                        }
                        else
                        {
                            RectangleList[i].Decrease(RectangleList[i].MyRec.Height);
                        }

                        if (RectangleList[i].Check == true)
                        {
                            RectangleList[i].increaseypos((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                            RectangleList[i].Move((int)RectangleList[i].YPos);
                        }
                    }
                    if (RectangleList[i].MyRec.Y >= Button_Y_Position - (4 + (6 * Myspeed)) && RectangleList[i].Check == true && RectangleList[i].Hit == true && RectangleList[i].ChangeButton == false)
                    {
                        if (WhiteKey.Contains(RectangleList[i].Position))
                        {
                            buttonlist[RectangleList[i].Position - 1].BackColor = Color.White;
                        }
                        else
                        {
                            buttonlist[RectangleList[i].Position - 1].BackColor = Color.Black;
                        }
                        outDevice.Send(new ChannelMessage(ChannelCommand.NoteOff, 0, RectangleList[i].Position + 20, 0));
                        RectangleList[i].ChangeButton = true;
                        RectangleList.RemoveAt(i);
                    }
                }
                else
                {
                    //Increasing the Height from 0 to the height of note
                    if (RectangleList[i].MyRec.Height < (RectangleList[i].Period / 5) && RectangleList[i].Check == false)
                    {
                        RectangleList[i].increasespeed((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                        RectangleList[i].IncreaseHeight((int)RectangleList[i].Speed);
                    }

                    else
                    {
                        RectangleList[i].Check = true; //Rectangle is in the full height
                    }
                    //Decreasing the Height when touching the button
                    if (RectangleList[i].MyRec.Height + RectangleList[i].MyRec.Y >= Button_Y_Position && RectangleList[i].MyRec.Height > 0)
                    {
                        RectangleList[i].decreaseheight((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                        RectangleList[i].Decrease((int)RectangleList[i].Height);
                    }

                    //Moving Rectangle down
                    if (RectangleList[i].MyRec.Y <= Button_Y_Position && RectangleList[i].Check == true)
                    {
                        RectangleList[i].increaseypos((((double)RectangleList[i].Period * timer1.Interval * speed / (double)5) / ((double)RectangleList[i].Period)));
                        RectangleList[i].Move((int)RectangleList[i].YPos);

                        //Playing Note and changing the color of button
                        if (RectangleList[i].MyRec.Height + RectangleList[i].MyRec.Y >= Button_Y_Position && RectangleList[i].Hit == false)
                        {
                            outDevice.Send(new ChannelMessage(ChannelCommand.NoteOn, 0, RectangleList[i].Position + 20, 127));//playing note
                            if (!play)
                            {
                                play = true;
                            }
                            //change the color of button
                            if (WhiteKey.Contains(RectangleList[i].Position))
                            {
                                if (RectangleList[i].Position <= 44)
                                {
                                    buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                                }
                                else
                                {
                                    buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                                }
                            }
                            else
                            {
                                if (RectangleList[i].Position <= 44)
                                {
                                    buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                                }
                                else
                                {
                                    buttonlist[RectangleList[i].Position - 1].BackColor = RectangleList[i].Color.Color;
                                }
                            }
                            RectangleList[i].Hit = true;
                        }
                    }

                    //returning color of button to original color
                    if (RectangleList[i].MyRec.Y >= Button_Y_Position - (4 + (6 * Myspeed)) && RectangleList[i].Check == true && RectangleList[i].Hit == true && RectangleList[i].ChangeButton == false)
                    {
                        if (WhiteKey.Contains(RectangleList[i].Position))
                        {
                            buttonlist[RectangleList[i].Position - 1].BackColor = Color.White;
                        }
                        else
                        {
                            buttonlist[RectangleList[i].Position - 1].BackColor = Color.Black;
                        }
                        outDevice.Send(new ChannelMessage(ChannelCommand.NoteOff, 0, RectangleList[i].Position + 20, 0));
                        RectangleList[i].ChangeButton = true;
                        RectangleList.RemoveAt(i);
                    }
                }
            }
        }