Esempio n. 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.


            View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("BackMain.jpg"));

            //--------Staff set up---------

            //notePositions will tell us where to draw staff in case sizes, positions change, noteHieght lets us find mid point
            int[] notePositions = { (int)Btn_FP1.Frame.Y, (int)Btn_D.Frame.Y, (int)Btn_B.Frame.Y, (int)Btn_G.Frame.Y, (int)Btn_E.Frame.Y };
            int   noteHeight    = (int)Btn_FP1.Frame.Height;
            int   staffOffset   = (int)(Btn_FP1.Frame.X * .9);

            //start of staff will be based on second E + width and will go down 90% from top, end points will be entire screen minus offsets and bottom E note
            layout = new StaffViewer(new CGRect(Btn_EP1.Frame.X + Btn_EP1.Frame.Width, (int)(Btn_FP1.Frame.X * .9), UIScreen.MainScreen.Bounds.Width - Btn_FP1.Frame.X - (Btn_EP1.Frame.X + Btn_EP1.Frame.Width), Btn_E.Frame.Y + Btn_E.Frame.Height), notePositions, noteHeight, staffOffset);

            //-----Staff set up end--------

            //-----Handle stepper for tempo---------------
            stepper_tempo.ValueChanged += (object sender, EventArgs e) =>
            {
                txtTempo.Text = stepper_tempo.Value.ToString();
                currentTempo  = Convert.ToInt32(stepper_tempo.Value.ToString());
            };

            txtTempo.ShouldChangeCharacters += (UITextField textfield, NSRange range, string replacement) =>
            {
                string combine = textfield.Text + replacement;

                if (combine.Equals(""))
                {
                    combine = "0";
                }

                double newVal = Convert.ToDouble(combine);

                if (newVal >= 30.0 && newVal <= 180.0)
                {
                    stepper_tempo.Value = newVal;
                }
                else if (newVal < 30.0)
                {
                    stepper_tempo.Value = 30.0;
                }
                else
                {
                    stepper_tempo.Value = 180.0;
                }

                currentTempo = Convert.ToInt32(stepper_tempo.Value.ToString());

                return(true);
            };

            //-----Handle Button Presses--------

            Btn_Math.TouchUpInside += (object sender, EventArgs e) =>
            {
            };

            //---------Save/Load file-------
            btn_Save.TouchUpInside += (object sender, EventArgs e) =>
            {
                var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var filename  = Path.Combine(documents, txt_name.Text);
                File.WriteAllText(filename, currentMelody + ":" + currentTempo);
            };

            btn_Load.TouchUpInside += (object sender, EventArgs e) =>
            {
                var       documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var       filename  = Path.Combine(documents, txt_Load.Text);
                string[]  splitData = { ":" };
                string [] txtData   = File.ReadAllText(filename).Split(splitData, StringSplitOptions.RemoveEmptyEntries);
                currentMelody       = txtData[0];
                currentTempo        = Convert.ToInt32(txtData[1]);
                stepper_tempo.Value = currentTempo;
                txtTempo.Text       = currentTempo.ToString();
                layout.SetMelody(currentMelody);
                layout.SetNeedsDisplay();
            };
            //-------end file save/load----------

            //----Play/Remove buttons---------
            PlayButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                //MidiPlayer player = new MidiPlayer();
                //player.play("C|1|1,A|1|0,C|.25|1,A|.25|0,C|.25|1,A|.25|0", 60);
                player.play(currentMelody, currentTempo);
            };

            Btn_Remove.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("", "", "R");
            };
            //-----end Play/Remove Buttons------

            //-----Instrument buttons------------
            Btn_Piano.TouchUpInside += (object sender, EventArgs e) =>
            {
                player.SetInstrument("piano");
            };

            Btn_Choir.TouchUpInside += (object sender, EventArgs e) =>
            {
                player.SetInstrument("voice");
            };

            Btn_Guitar.TouchUpInside += (object sender, EventArgs e) =>
            {
                player.SetInstrument("guitar");
            };

            Btn_Bass.TouchUpInside += (object sender, EventArgs e) =>
            {
                player.SetInstrument("bass");
            };
            //----end instrument buttons----------


            //---Note Value Buttons---------
            Btn_NoteWhole.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageNoteButtons(Btn_NoteWhole);
            };

            Btn_Half.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageNoteButtons(Btn_Half);
            };

            Btn_Quarter.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageNoteButtons(Btn_Quarter);
            };

            Btn_Eighth.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageNoteButtons(Btn_Eighth);
            };

            Btn_Sixteen.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageNoteButtons(Btn_Sixteen);
            };
            //----end note value buttons------

            //----Note Pitch Buttons---------
            Btn_D0.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("D", "0", "A");
            };

            Btn_E.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("E", "0", "A");
            };

            Btn_F.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("F", "0", "A");
            };

            Btn_G.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("G", "0", "A");
            };

            Btn_A.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("A", "0", "A");
            };

            Btn_B.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("B", "0", "A");
            };

            Btn_C.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("C", "1", "A");
            };

            Btn_D.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("D", "1", "A");
            };

            Btn_EP1.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("E", "1", "A");
            };

            Btn_FP1.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("F", "1", "A");
            };

            Btn_G1.TouchUpInside += (object sender, EventArgs e) =>
            {
                ManageMelody("G", "1", "A");
            };
            //----end note pitch buttons--------

            //------end Handle Button presses-----------

            //add the view to the main view
            //var layout = new StaffViewer(new CGRect(100, 50, UIScreen.MainScreen.Bounds.Width - 100, UIScreen.MainScreen.Bounds.Height - 400));
            //layout.BackgroundColor = UIColor.Red;
            View.AddSubview(layout);
        }
Esempio n. 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            vwFeedback.Layer.BorderColor = UIColor.Black.CGColor;
            vwFeedback.Layer.BorderWidth = (nfloat)1.0;

            //--------Staff set up---------

            //notePositions will tell us where to draw staff in case sizes, positions change, noteHieght lets us find mid point
            int[] notePositions = { (int)Btn_FP1.Frame.Y, (int)Btn_D.Frame.Y, (int)Btn_B.Frame.Y, (int)Btn_G.Frame.Y, (int)Btn_E.Frame.Y };
            int   noteHeight    = (int)Btn_FP1.Frame.Height;
            int   staffOffset   = (int)(Btn_FP1.Frame.X * .9);

            //start of staff will be based on second E + width and will go down 90% from top, end points will be entire screen minus offsets and bottom E note
            layout = new StaffViewer(new CGRect(Btn_EP1.Frame.X + Btn_EP1.Frame.Width, (int)(Btn_FP1.Frame.X * .9), UIScreen.MainScreen.Bounds.Width - Btn_FP1.Frame.X - (Btn_EP1.Frame.X + Btn_EP1.Frame.Width), Btn_E.Frame.Y + Btn_E.Frame.Height), notePositions, noteHeight, staffOffset);

            layout.SetMelody(MelodyInfo[0]);
            layout.SetNeedsDisplay();

            View.AddSubview(layout);

            //-----Staff set up end--------

            board = new Whiteboard {
                Frame = new CGRect(0, vwFeedback.Frame.Y + vwFeedback.Frame.Height, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height)
            };                                                                                                                                                                   //UIScreen.MainScreen.Bounds };
            View.AddSubview(board);

            btn_Submit.TouchUpInside += (object sender, EventArgs e) =>
            {
                string message = "";
                if (answer.Equals(txt_Answer.Text))
                {
                    message = "Correct! Good Job!";
                }
                else
                {
                    message = "Try Again!";
                }

                lbl_vwMsg.Text    = message;
                vwFeedback.Hidden = false;

                if (lbl_vwMsg.Text.Equals("No"))
                {
                    var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    var filename  = Path.Combine(documents, "MelodicMath_Errors");
                    File.AppendAllText(filename, question + ":" + answer + ":" + txt_Answer.Text);
                }
            };

            btn_vwOK.TouchUpInside += (object sender, EventArgs e) =>
            {
                vwFeedback.Hidden = true;
                lbl_vwMsg.Text    = "";
            };

            btn_Hint.TouchUpInside += (object sender, EventArgs e) =>
            {
                lbl_Hint.Text = formula;
            };

            btn_New.TouchUpInside += (object sender, EventArgs e) =>
            {
                GenerateQuestion();
            };

            GenerateQuestion();

            /*
             * questionInfo = mGen.Generate(MelodyInfo);
             * question = questionInfo[0];
             * answer = questionInfo[1];
             * formula = questionInfo[2];
             * lblMathQuestion.Text = questionInfo[0];
             */
        }