MCPcopy Create free account
hub / github.com/SFML/SFML / main

Function main

examples/sound_device/SoundDevice.cpp:21–248  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Entry point of application \return Application exit code ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

19///
20////////////////////////////////////////////////////////////
21int main()
22{
23 // List the available playback devices
24 auto devices = sf::PlaybackDevice::getAvailableDevices();
25
26 if (devices.empty())
27 {
28 std::cout << "No playback devices available\n";
29 return EXIT_FAILURE;
30 }
31
32 std::cout << "Available playback devices:\n\n";
33
34 for (auto i = 0u; i < devices.size(); ++i)
35 std::cout << i << ": " << devices[i] << '\n';
36
37 std::cout << '\n';
38
39 // Output the default device name if one is available
40 const auto defaultDevice = sf::PlaybackDevice::getDefaultDevice();
41
42 if (defaultDevice)
43 std::cout << "Default device: " << *defaultDevice << '\n';
44
45 std::cout << std::endl;
46
47 std::size_t deviceIndex = 0;
48
49 // Choose the playback device
50 if (devices.size() > 1)
51 {
52 deviceIndex = devices.size();
53 std::cout << "Please choose the playback device to use [0-" << devices.size() - 1 << "]: ";
54 do
55 {
56 std::cin >> deviceIndex;
57 std::cin.ignore(10'000, '\n');
58 } while (deviceIndex >= devices.size());
59 }
60
61 // Check if we can and whether the user wants to enable automatic stream routing
62 bool automaticStreamRouting = false;
63
64 if (devices[deviceIndex] == defaultDevice)
65 {
66 char answer{};
67 std::cout << "Activate automatic stream routing? (Y/N): ";
68 do
69 {
70 std::cin >> answer;
71 std::cin.ignore(10'000, '\n');
72 } while (answer != 'Y' && answer != 'y' && answer != 'N' && answer != 'n');
73 automaticStreamRouting = (answer == 'Y') || (answer == 'y');
74 }
75
76 // Check if we should manually reroute to the default device or the null device
77 bool rerouteToNull = false;
78

Callers

nothing calls this directly

Calls 12

getAvailableDevicesFunction · 0.85
getDefaultDeviceFunction · 0.85
setDeviceToDefaultFunction · 0.85
setDeviceFunction · 0.85
setNotificationCallbackFunction · 0.85
getDeviceFunction · 0.85
isDefaultDeviceFunction · 0.85
setDeviceToNullFunction · 0.85
setLoopingMethod · 0.45
playMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected