Beispiel #1
0
        public void Piano_FindKeys_WhenOctaveDoesNotExist_ShouldReturnEmptyList()
        {
            // Arrange
            Piano p = new Piano();

            // Act
            List <PianoKey> pks = p.FindKeys(Piano.BASE_OCTAAF + Piano.OCTAVEN, false);

            // Assert
            Assert.IsNotNull(pks);
            Assert.AreEqual(0, pks.Count);
        }
Beispiel #2
0
        public void Piano_FindKeys_WhenOctaveExists_WhenSearchingForWhiteKeys_ShouldReturnSevenWhiteKeys()
        {
            // Arrange
            Piano p = new Piano();

            // Act
            List <PianoKey> pks = p.FindKeys(Piano.BASE_OCTAAF, false);

            // Assert
            Assert.AreEqual(7, pks.Count);
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "C")));
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "D")));
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "E")));
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "F")));
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "G")));
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "A")));
            Assert.IsTrue(pks.Contains(new PianoKey(Piano.BASE_OCTAAF, "B")));
        }
        // Renderer functies
        public static void RenderPiano(Piano p, Size z, Graphics g)
        {
            // Bereken of pak wat standaard variabelen
            int top     = (z.Height / 2) - (PIANO_HEIGHT / 2);
            int left    = (z.Width / 2) - (PIANO_WIDTH / 2);
            int octaves = Piano.OCTAVEN;

            // Achtergrond legen
            g.FillRectangle(BRUSH_PROGRESS, left, top, PIANO_WIDTH, PIANO_HEIGHT);

            // Houdt bij waar we aan het tekenen zijn
            int x = left;
            int y = top;

            // Render alle octaves van de Piano
            for (int oct = 0; oct < octaves; oct++)
            {
                // Pak alle witte toetsen van dit octave
                List <PianoKey> whiteKeys = p.FindKeys(Piano.BASE_OCTAAF + oct, false);

                // Render alle witte toetsen van de Piano
                for (int k = 0; k < whiteKeys.Count; k++)
                {
                    PianoKey key = whiteKeys[k];
                    int      rx  = x + ((oct * 7) + k) * WHITE_KEY_FULL_WIDTH;

                    // Zet de Rectangle op
                    RECT.X      = rx;
                    RECT.Y      = y;
                    RECT.Width  = WHITE_KEY_FULL_WIDTH;
                    RECT.Height = WHITE_KEY_HEIGHT;

                    // Teken de achtergrondkleur
                    g.FillRectangle(
                        key.Enabled ? BRUSH_PROGRESS : BRUSH_BACKGROUND,
                        RECT
                        );

                    // Teken de rand
                    g.DrawRectangle(
                        PEN,
                        RECT
                        );

                    // Zorg dat we relatief tot de onderkant werken en limiteer de hoogte
                    RECT.Y      = RECT.Bottom;
                    RECT.Height = PIANO_TEXT_HEIGHT;
                    RECT.Y     -= RECT.Height;

                    // Teken de tekst
                    g.DrawString(key.Name + key.Octave, FONT, BRUSH, RECT, STRING_FORMAT);
                }

                // Render alle witte toetsen van de Piano
                List <PianoKey> blackKeys = p.FindKeys(Piano.BASE_OCTAAF + oct, true);

                // Render alle zwarte toetsen van de Piano
                for (int k = 0; k < blackKeys.Count; k++)
                {
                    // Pak de toets
                    PianoKey key = blackKeys[k];
                    int      rx  = x + WHITE_KEY_FULL_WIDTH - (BLACK_KEY_FULL_WIDTH / 2) + (((oct * 7) + (k >= 2 ? k + 1 : k)) * WHITE_KEY_FULL_WIDTH);

                    // Zet de Rectangle op
                    RECT.X      = rx;
                    RECT.Y      = y;
                    RECT.Width  = BLACK_KEY_FULL_WIDTH;
                    RECT.Height = BLACK_KEY_HEIGHT;

                    // Teken de achtergrondkleur
                    g.FillRectangle(key.Enabled ? BRUSH_PROGRESS : BRUSH, RECT);

                    // Teken de randjes
                    g.DrawRectangle(PEN, RECT);

                    // Zorg dat we relatief tot de onderkant werken en limiteer de hoogte
                    RECT.Y      = RECT.Bottom;
                    RECT.Height = PIANO_TEXT_HEIGHT;
                    RECT.Y     -= RECT.Height;

                    // Teken de tekst
                    g.DrawString(key.Name + key.Octave, FONT, BRUSH_BACKGROUND, RECT, STRING_FORMAT);
                }
            }
        }