Browse Source

Audio: add support for quiet logging in Context.

pull/362/head
Guillaume Jacquemin 7 years ago
parent
commit
e2c14407a6
  1. 17
      src/Magnum/Audio/Context.cpp
  2. 51
      src/Magnum/Audio/Context.h

17
src/Magnum/Audio/Context.cpp

@ -4,6 +4,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2015 Jonathan Hale <squareys@googlemail.com>
Copyright © 2019 Guillaume Jacquemin <williamjcm@users.noreply.github.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -32,6 +33,7 @@
#include <alc.h>
#include <cstring>
#include <Corrade/Utility/Arguments.h>
#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/DebugStl.h>
@ -120,12 +122,15 @@ Context& Context::current() {
return *_current;
}
#ifndef DOXYGEN_GENERATING_OUTPUT
Context::Context(): Context{Configuration{}} {}
#endif
Context::Context(Int argc, const char** argv): Context(Configuration{}, argc, argv) {}
Context::Context(NoCreateT, Int argc, const char** argv): Context(NoCreate) {
Utility::Arguments args{"magnum"};
args.addOption("log", "default").setHelp("log", "console logging", "default|quiet|verbose")
.setFromEnvironment("log")
.parse(argc, argv);
Context::Context(const Configuration& configuration) {
create(configuration);
_displayInitializationLog = !(args.value("log") == "quiet" || args.value("log") == "QUIET");
}
Context::Context(NoCreateT) noexcept: _device{}, _context{} {}
@ -211,9 +216,11 @@ bool Context::tryCreate(const Configuration& configuration) {
}
}
if(_displayInitializationLog) {
/* Print some info */
Debug() << "Audio Renderer:" << rendererString() << "by" << vendorString();
Debug() << "OpenAL version:" << versionString();
}
return true;
}

51
src/Magnum/Audio/Context.h

@ -6,6 +6,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2015 Jonathan Hale <squareys@googlemail.com>
Copyright © 2019 Guillaume Jacquemin <williamjcm@users.noreply.github.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -158,22 +159,42 @@ class MAGNUM_AUDIO_EXPORT Context {
/**
* @brief Constructor
*
* Creates OpenAL context with given configuration.
* Parses command-line arguments, and creates OpenAL context with given
* configuration.
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit Context(const Configuration& configuration = Configuration());
#else
explicit Context(const Configuration& configuration);
explicit Context();
#endif
explicit Context(const Configuration& configuration, Int argc, const char** argv): Context(NoCreate, argc, argv) { create(configuration); }
/**
* @brief Construct without creating the underlying OpenAL context
*
* Useful in cases where you need to defer context creation to a later
* time, for example to do a more involved configuration. Call
* @ref create() or @ref tryCreate() to create the actual context.
*/
/** @overload */
explicit Context(const Configuration& configuration, Int argc, char** argv): Context(configuration, argc, const_cast<const char**>(argv)) {}
/** @overload */
explicit Context(const Configuration& configuration, Int argc, std::nullptr_t argv): Context(configuration, argc, static_cast<const char**>(argv)) {}
/** @overload */
explicit Context(const Configuration& configuration): Context(configuration, 0, nullptr) {}
/** @overload */
explicit Context(Int argc, const char** argv);
/** @overload */
explicit Context(Int argc, char** argv): Context(argc, const_cast<const char**>(argv)) {}
/** @overload */
explicit Context(Int argc, std::nullptr_t argv): Context(argc, static_cast<const char**>(argv)) {}
/** @overload */
explicit Context(): Context(0, nullptr) {}
/** @overload */
explicit Context(NoCreateT, Int argc, const char** argv);
/** @overload */
explicit Context(NoCreateT, Int argc, char** argv): Context(NoCreate, argc, const_cast<const char**>(argv)) {}
/** @overload */
explicit Context(NoCreateT, Int argc, std::nullptr_t argv): Context(NoCreate, argc, static_cast<const char**>(argv)) {}
/** @overload */
explicit Context(NoCreateT) noexcept;
/** @brief Copying is not allowed */
@ -331,6 +352,8 @@ class MAGNUM_AUDIO_EXPORT Context {
private:
MAGNUM_AUDIO_LOCAL static Context* _current;
bool _displayInitializationLog;
ALCdevice* _device;
ALCcontext* _context;

Loading…
Cancel
Save