Display a color for each audio file?

I have this little program I made that randomly plays audio files. Does anyone know the easiest way to display a full-screen hex background color in the terminal for each sound file that plays? I want a specific background color attached to each file, so that the color is displayed every time the file plays. I want the terminal just one solid color, no text or anything else.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <windows.h>
#include <mmsystem.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <random>
#include <algorithm>

using namespace std;

int main() {
    string e2 = "e2.wav";
    string a2 = "a2.wav";
    string d3 = "d3.wav";
    string g3 = "g3.wav";
    string b3 = "b3.wav";
    string e4 = "e4.wav";
    auto ints = vector<string> { "e2.wav", "a2.wav", "d3.wav", "g3.wav", "b3.wav", "e4.wav" };

    auto rng = default_random_engine {};
    while ( true ) {
    shuffle(ints.begin(), ints.end(), rng);

    for (auto i : ints) {
        PlaySound((LPCTSTR) i.c_str(), NULL, SND_SYNC);
    }
}
}
Last edited on
https://docs.microsoft.com/en-us/windows/console/console-functions

But your choice of colours is somewhat limited.
http://forums.codeguru.com/showthread.php?539241-RESOLVED-can-anyone-tell-me-all-colors-const-for-SetConsoleTextAttribute()-function

But you might be able to synthesis some other colours by dithering f/g and b/g with
https://en.wikipedia.org/wiki/Block_Elements
U+2591 ░ Light shade
U+2592 ▒ Medium shade
U+2593 ▓ Dark shade

As for picking colours from filenames, perhaps a hash
https://en.cppreference.com/w/cpp/utility/hash


@M22878,

IMO it might be easier to create a bare-bones Win32 API window, changing the client area's background color is easy vs. doing it in a command prompt console window.

Especially since your app isn't taking any input from the user. Just launch and listen.
@Furry Guy Okay, I will try that. But how do I assign each color to an audio file? Would I do that with a loop of some kind? Like, if g3.wav then background color is #FF0000 or something like that?
You have a list of WAV files to play, you create a list of the colors you want.

https://stackoverflow.com/questions/3463471/how-to-set-background-color-of-window-after-i-have-registered-it

Best I can suggest is find some tutorials that will step you through the basics of Win32 API programming.

theForger's may be old, but it still will give you the basics.

http://www.winprog.org/tutorial/
Okay, I will try that. But how do I assign each color to an audio file? Would I do that with a loop of some kind? Like, if g3.wav then background color is #FF0000 or something like that?

If you want the assignment of colour to file to be done inside your C++ code, I'd use a std::map, using the filenames as keys, as the colours as values. Then, then you display a particular filename, you can easily obtain the appropriate colour from the map.
Topic archived. No new replies allowed.