示例#1
0
        public MainPage(String songStringFromUrl = null)
        {
            InitializeComponent();
            BackgroundColor = Color.FromHex("#000000");           //* Set page style
            NavigationPage.SetHasNavigationBar(this, false);      //*
            DependencyService.Get <IStatusBar>().HideStatusBar(); // Make sure status bar is hidden

            MakeStepGrid();

            //PinchGestureRecognizer pinchRecognizer = new PinchGestureRecognizer();  //
            //pinchRecognizer.PinchUpdated += HandlePinch;                            // Handle when user pinches
            //stepgrid.GestureRecognizers.Add(pinchRecognizer);                       //

            // Initialize the SongPlayer
            player = new SongPlayer();

            //Load default tempo and instruments, and if this is the first time the user has launched the app, show the startup song
            Song startSong = FileUtilities.LoadSongFromStream(FileUtilities.LoadEmbeddedResource("firsttimesong.txt"));

            if (!Directory.Exists(FileUtilities.PathToSongDirectory))
            {
                Directory.CreateDirectory(FileUtilities.PathToSongDirectory);
                this.song          = startSong;
                lastLoadedSongName = "Initial beat";
                UpdateStepGridToMatchSong();
                FileUtilities.SaveSongToFile(startSong, "Initial beat");
                firstTime = true;
            }
            else
            {
                song      = new Song(NumColumns, startSong.Instruments, startSong.Tempo);
                firstTime = false;
            }

            if (songStringFromUrl != null)
            {
                firstTime = false;

                song = FileUtilities.GetSongFromSongString(songStringFromUrl);
                UpdateStepGridToMatchSong();
            }

            playImageName = App.isTablet ? "play_Tab.png" : "play.png";
            stopImageName = App.isTablet ? "stop_Tab.png" : "stop.png";
            MakeSideBar();

            // Initialize the highlight box
            highlights = new BoxView[2];
            for (int i = 0; i < 2; i++)
            {
                highlights[i] = new BoxView()
                {
                    Color = Color.White, Opacity = brightnessIncrease, InputTransparent = true
                };
            }
            player.BeatStarted += HighlightColumns;         // Add an event listener to keep highlight in time with beat


            //Set up a master grid with 3 columns and 2 rows to eventually place stepgrid, sidebar, and scrollbars in.
            mastergrid = new Grid {
                ColumnSpacing = 2, RowSpacing = 2
            };
            mastergrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(14, GridUnitType.Absolute)
            });                                                                                                            //spot for up-down scrollbar
            mastergrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(8, GridUnitType.Star)
            });                                                                                                       // spot for stepgrid
            mastergrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                                       // spot for sidebar
            mastergrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                                  // horizontal spot for everything, but side scrollbar
            mastergrid.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(14, GridUnitType.Absolute)
            });                                                                                                       // spot for side scrollbar


            // Make vertical scrollbar, size doesn't matter because constraints are used to size it later
            verticalScrollBar = new BoxView
            {
                BackgroundColor = Color.FromHex("D3D3D3"),
                WidthRequest    = 1,
                HeightRequest   = 1,
            };


            // Make vertical scrollbar
            horizontalScrollBar = new BoxView
            {
                BackgroundColor = Color.FromHex("D3D3D3"),
                WidthRequest    = 1,
                HeightRequest   = 1,
            };


            // This calculates the pixel values for the width and height of the whole scroller (including offscreen)
            scrollerActualHeight = (miniGridHeight + stepGridSpacing) * NumRows - stepGridSpacing;
            scrollerActualWidth  = (miniGridWidth + stepGridSpacing) * NumColumns - stepGridSpacing;


            // Initialize scrollview and put stepgrid inside it
            scroller = new ScrollView
            {
                Orientation = ScrollOrientation.Both  //Both vertical and horizontal orientation
            };

            scroller.Content = stepgrid;

            mastergrid.Children.Add(scroller, 1, 0);

            // Make the Relative layouts that will hold the sidebars and place them in their proper positions in mastergrid
            verticalBarArea = new RelativeLayout();
            mastergrid.Children.Add(verticalBarArea, 0, 0);

            horizontalBarArea = new RelativeLayout();
            mastergrid.Children.Add(horizontalBarArea, 1, 1);

            DrawScrollBar(horizontalScrollBar);
            DrawScrollBar(verticalScrollBar);


            //scroller.Scrolled += UpdateScrollBars;              // Scrolled event that calls method to update scrollbars
            scroller.Scrolled += BoundedScroll;

            mastergrid.Children.Add(sidebar, 2, 0);             // Add sidebar to final column of mastergrid
            Grid.SetRowSpan(sidebar, 2);                        //make sidebar take up both rows in rightmost column


            Content = mastergrid;
        }
示例#2
0
        public MainPage()
        {
            InitializeComponent();

            // Initializing the song player and noteArray
            noteArray = new SongPlayer.Note[NumColumns, NumRows];       //stored this way because C# is row-major and we want to access a column at a time
            player    = new SongPlayer(noteArray);

            // Initializing the colorMap
            colorMap = new Dictionary <Color, SongPlayer.Instrument>();

            colorMap[Red]    = player.LoadInstrument("Snare");
            colorMap[Blue]   = player.LoadInstrument("YRM1x Atmosphere");
            colorMap[Green]  = player.LoadInstrument("Bass Drum");
            colorMap[Yellow] = player.LoadInstrument("Hi-Hat");

            // Initialize color of highlighted buttons
            highLightedGrey   = HighLightedVersion(Grey);
            highLightedRed    = HighLightedVersion(Red);
            highLightedBlue   = HighLightedVersion(Blue);
            highLightedGreen  = HighLightedVersion(Green);
            highLightedYellow = HighLightedVersion(Yellow);

            // Initaialize the array of buttons
            buttonArray = new Button[NumColumns, NumRows];  //stored this way because C# is row-major and we want to access a column at a time

            BackgroundColor = Color.FromHex("#000000");     // Make background color black

            Style greyButton = new Style(typeof(Button))    // Button style for testing grid
            {
                Setters =
                {
                    new Setter {
                        Property = Button.BackgroundColorProperty, Value = Grey
                    },
                    new Setter {
                        Property = Button.BorderRadiusProperty, Value = 0
                    },
                }
            };

            //Set up a master grid with 2 columns to eventually place stepgrid and sidebar in.
            mastergrid = new Grid {
                ColumnSpacing = 2
            };
            mastergrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(8, GridUnitType.Star)
            });
            mastergrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });


            //Set up grid of note squares
            stepgrid = new Grid {
                ColumnSpacing = 2, RowSpacing = 2
            };

            //Initialize the number of rows and columns
            for (int i = 0; i < NumRows; i++)
            {
                stepgrid.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
            for (int i = 0; i < NumColumns; i++)
            {
                stepgrid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            //Add the note buttons to the grid
            for (int i = 0; i < NumRows; i++)
            {
                for (int j = 0; j < NumColumns; j++)
                {
                    Button button = new Button {
                        Style = greyButton
                    };                                                  // Make a new button
                    stepgrid.Children.Add(button, j, i);                // Add it to the grid
                    button.Clicked   += OnButtonClicked;                // Add it to stepsquare event handler
                    noteArray[j, i]   = SongPlayer.Note.None;           // Add a placeholder to songArray
                    buttonArray[j, i] = button;                         // Add button to buttonArray
                }
            }


            // Make the sidebar
            sidebar = new Grid {
                ColumnSpacing = 1, RowSpacing = 1
            };

            for (int i = 0; i < NumInstruments; i++)
            {
                sidebar.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(1, GridUnitType.Star)
                });
            }
            sidebar.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            // Fill sidebar it with buttons
            Color[] colors = new Color[] { Red, Blue, Green, Yellow };                  // Array of colors

            for (int i = 0; i < colors.Length; i++)
            {
                Button button = new Button {
                    BackgroundColor = colors[i], BorderColor = Color.Black, BorderWidth = 3
                };                                                                                  // Make a new button
                sidebar.Children.Add(button, 0, i);                                                 // Add it to the sidebar
                button.Clicked += OnSidebarClicked;                                                 // Add to sidebar event handler
            }


            // Set up scroll view and put grid inside it
            scroller = new ScrollView {
                Orientation = ScrollOrientation.Vertical                  //Both vertical and horizontal orientation
            };
            scroller.Content = stepgrid;

            // Add the scroller (which contains stepgrid) and sidebar to mastergrid
            mastergrid.Children.Add(scroller, 0, 0); // Add scroller to first column of mastergrid
            mastergrid.Children.Add(sidebar, 1, 0);  // Add sidebar to final column of mastergrid
                                                     //Grid.SetRowSpan(sidebar, NumRows);                  // Make sure that it spans the whole column

            Content             = mastergrid;
            player.BeatStarted += HighlightColumns;
            player.BeginPlaying(240);
        }