xtd 0.2.0
Loading...
Searching...
No Matches
xtd::beep Class Referencefinal
Inheritance diagram for xtd::beep:
xtd::object

Definition

Represent beep output manipulator class.

Header
#include <xtd/beep>
Namespace
xtd
Library
xtd.core
See also
xtd::console::beep method.
Examples
console_beep2.cpp, and console_beep3.cpp.

Public Constructors

 beep ()=default
 Plays the sound of a beep through the console speaker.
 
 beep (uint32 frequency, uint32 duration)
 Plays the sound of a beep of a specified frequency and duration through the console speaker.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const noexcept
 Returns a xtd::string that represents the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ beep() [1/2]

xtd::beep::beep ( )
default

Plays the sound of a beep through the console speaker.

Remarks
By default, the beep plays at a frequency of 800 hertz for a duration of 200 milliseconds
Examples
The following example demonstrates the beep method. The example accepts a number from 1 through 9 as a command line argument, and plays the beep that number of times.
#include <xtd/threading/thread>
#include <xtd/beep>
#include <xtd/console>
#include <xtd/environment>
#include <xtd/int32_object>
#include <xtd/literals>
using namespace xtd;
auto main(int argc, char* argv[]) -> int {
int x = 0;
//
if ((argc == 2) && (int32_object::try_parse(argv[1], x) == true) && ((x >= 1) && (x <= 9))) {
for (auto i = 1; i <= x; i++) {
console::out << string::format("Beep number {}.", i) << beep() << environment::new_line;
}
} else
console::out << "Usage: Enter the number of times (between 1 and 9) to beep." << environment::new_line;
}
beep()=default
Plays the sound of a beep through the console speaker.
static bool try_parse(const xtd::string &value, type_t &result) noexcept
Converts the string to its type_t equivalent. A return value indicates whether the conversion succeed...
Definition box.h:133
static std::ostream out
Gets the standard output stream. A std::basic_ostream<char_t> that represents the standard output str...
Definition console.h:52
static xtd::string new_line() noexcept
Gets the newline string defined for this environment.
static void sleep(int32 milliseconds_timeout)
Suspends the current thread for a specified time.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
@ i
The I key.
@ x
The X key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10

◆ beep() [2/2]

xtd::beep::beep ( uint32  frequency,
uint32  duration 
)
inline

Plays the sound of a beep of a specified frequency and duration through the console speaker.

Parameters
frequencyThe frequency of the beep, ranging from 37 to 32767 hertz
durationThe duration of the beep measured in milliseconds
Examples
This example demonstrates the beep method by playing the first few notes of a song through the console speaker.
#include <xtd/collections/generic/list>
#include <xtd/threading/thread>
#include <xtd/as>
#include <xtd/beep>
#include <xtd/console>
using namespace xtd;
using namespace xtd::collections::generic;
// Define the frequencies of notes in an octave, as well as
// silence (rest).
enum class tone {
rest = 0,
g_below_c = 196,
a = 220,
a_sharp = 233,
b = 247,
c = 262,
c_sharp = 277,
d = 294,
d_sharp = 311,
e = 330,
f = 349,
f_sharp = 370,
g = 392,
g_sharp = 415,
};
// Define the duration of a note in units of milliseconds.
enum class duration {
none = 0,
whole = 1600,
half = whole / 2,
quarter = half / 2,
eighth = quarter / 2,
sixteenth = eighth / 2,
};
// Define a note as a frequency (tone) and the amount of
// time (duration) the note plays.
struct note final {
private:
tone tone_val = tone::rest;
duration dur_val = duration::none;
public:
// Define a constructor to create a specific note.
note(tone frequency, duration time) : tone_val(frequency), dur_val(time) {}
note() = default;
note(const note& note) = default;
note& operator=(const note& note) = default;
bool operator ==(const note& rhs) const noexcept {return tone_val == rhs.tone_val && dur_val == rhs.dur_val;}
// Define properties to return the note's tone and duration.
tone note_tone() const noexcept {return tone_val;}
duration note_duration() const noexcept {return dur_val;}
};
// Play the notes in a song.
void play(const list<note>& tune) {
for (auto n : tune) {
if (n.note_tone() == tone::rest)
threading::thread::sleep(as<int>(n.note_duration()));
else
console::out << beep(as<unsigned int>(n.note_tone()), as<unsigned int>(n.note_duration()));
}
}
auto main() -> int {
// Declare the first few notes of the song, "Mary Had A Little Lamb".
list mary = {
note(tone::b, duration::quarter),
note(tone::a, duration::quarter),
note(tone::g_below_c, duration::quarter),
note(tone::a, duration::quarter),
note(tone::b, duration::quarter),
note(tone::b, duration::quarter),
note(tone::b, duration::half),
note(tone::a, duration::quarter),
note(tone::a, duration::quarter),
note(tone::a, duration::half),
note(tone::b, duration::quarter),
note(tone::d, duration::quarter),
note(tone::d, duration::half)
};
// Play the song
play(mary);
}
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:71
@ none
No modifier key.
@ a
The A key.
@ c
The C key.
@ n
The N key.
@ d
The D key.
@ f
The F key.
@ b
The B key.
@ play
The Play key.
@ g
The G key.
@ e
The E key.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15

The documentation for this class was generated from the following file: