0

I am working on a project for school. I seem to be having an issue in VS 2019 and 2022 where the beep is not making any sound. When I start VS for the first time and run without debugging it works once then if I rerun the program with or without debugging the beep doesn't make a sound again until I restart VS. Even sometimes that doesn't work, I have to restart my computer. Any suggestions for a fix? Temp Piano.txt is a list of numbers that draws a GUI for a piano keyboard. Any help is much appreciated.

#include <iostream>
#include <string>
#include <conio.h>
#include <windows.h>
#include <fstream>
#include <cstdlib>

using namespace std;



void gotoxy(int column, int line)
{
    COORD coord;
    coord.X = column;
    coord.Y = line;
    SetConsoleCursorPosition(
        GetStdHandle(STD_OUTPUT_HANDLE),
        coord
    );
}
void ShowConsoleCursor(bool showFlag)
{
    HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO cursorInfo;
    GetConsoleCursorInfo(out, &cursorInfo);
    cursorInfo.bVisible = showFlag; // set the cursor visibility
    SetConsoleCursorInfo(out, &cursorInfo);
}
class stack
{
public:
    int H;
    char arr[20];
    stack() { H = 0; }
    void push(char c) { arr[H] = c; H++; };
    char pop() { H--; return arr[H]; }
};
void ColorBackground_C(int color)
{
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, color);
    for (int i = 20; i <= 29; i++)
    {
        for (int j = 3; j <= 48; j++)
        {
            gotoxy(i, j);
            cout << char(219);
        }
    }
}

void PlayNote(char note)
{
    //do re mi fa sol la si do re mi fa sol
    if (note == 'a') {
        Beep(261, 500);
    }
    if (note == 's') {
        Beep(293, 500);
    }
    if (note == 'd') {
        Beep(329, 500);
    }
    if (note == 'f') {
        Beep(349, 500);
    }
    if (note == 'g') {
        Beep(392, 500);
    }
    if (note == 'h') {
        Beep(440, 500);
    }
    if (note == 'j') {
        Beep(493, 500);
    }
    if (note == 'k') {
        Beep(523, 500);
    }
    if (note == 'l') {
        Beep(587, 500);
    }
    if (note == ';') {
        Beep(659, 500);
    }
    if (note == '\'') {
        Beep(698, 500);
    }
    if (note == '\\') {
        Beep(784, 500);
    }
    if (note == 'w') {
        Beep(277, 500);
    }
    if (note == 'e') {
        Beep(311, 500);
    }
    if (note == 't') {
        Beep(370, 500);
    }
    if (note == 'y') {
        Beep(415, 500);
    }
    if (note == 'u') {
        Beep(466, 500);
    }
    if (note == 'o') {
        Beep(554, 500);
    }
    if (note == 'p') {
        Beep(622, 500);
    }
    if (note == ']') {
        Beep(740, 500);
    }
}

void main()
{
    int value;
    int counter = 0;
    ifstream input;
    input.open("C:\\Data\\Temp Piano.txt");

    system("cls");
    while (!input.eof())
    {
        input >> value;
        cout << char(value);
        counter++;
        if (counter == 210)
        {
            cout << endl;
            counter = 0;
        }
    }

    input.close();

    while (1)
    {
        ColorBackground_C(14);
        PlayNote('j');
        Sleep(500);
        ColorBackground_C(0);
        Sleep(200);
    }
}
drescherjm
  • 10,365
  • 5
  • 44
  • 64

0 Answers0