-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
518 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 0BSD | ||
* | ||
* BSD Zero Clause License | ||
* | ||
* Copyright (c) 2020 Hermann Meyer | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted. | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
* PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
*/ | ||
|
||
|
||
#include "AnimatedKeyBoard.h" | ||
|
||
|
||
/**************************************************************** | ||
** class AnimatedKeyBoard | ||
** | ||
** animate midi input from jack on the keyboard in a extra thread | ||
** | ||
*/ | ||
|
||
namespace animatedkeyboard { | ||
|
||
AnimatedKeyBoard::AnimatedKeyBoard() | ||
:_execute(false) { | ||
} | ||
|
||
AnimatedKeyBoard::~AnimatedKeyBoard() { | ||
if( _execute.load(std::memory_order_acquire) ) { | ||
stop(); | ||
}; | ||
} | ||
|
||
void AnimatedKeyBoard::stop() { | ||
_execute.store(false, std::memory_order_release); | ||
if (_thd.joinable()) { | ||
_thd.join(); | ||
} | ||
} | ||
|
||
void AnimatedKeyBoard::start(int interval, std::function<void(void)> func) { | ||
if( _execute.load(std::memory_order_acquire) ) { | ||
stop(); | ||
}; | ||
_execute.store(true, std::memory_order_release); | ||
_thd = std::thread([this, interval, func]() { | ||
while (_execute.load(std::memory_order_acquire)) { | ||
func(); | ||
std::this_thread::sleep_for( | ||
std::chrono::milliseconds(interval)); | ||
} | ||
}); | ||
} | ||
|
||
bool AnimatedKeyBoard::is_running() const noexcept { | ||
return ( _execute.load(std::memory_order_acquire) && | ||
_thd.joinable() ); | ||
} | ||
|
||
} // namespace animatedkeyboard | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 0BSD | ||
* | ||
* BSD Zero Clause License | ||
* | ||
* Copyright (c) 2020 Hermann Meyer | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted. | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
* PERFORMANCE OF THIS SOFTWARE. | ||
* | ||
*/ | ||
|
||
|
||
#include <cstdlib> | ||
#include <functional> | ||
#include <thread> | ||
#include <atomic> | ||
|
||
#pragma once | ||
|
||
#ifndef ANIMATEDKEYBOARD_H | ||
#define ANIMATEDKEYBOARD_H | ||
|
||
/**************************************************************** | ||
** class AnimatedKeyBoard | ||
** | ||
** animate midi input from jack on the keyboard in a extra thread | ||
** | ||
*/ | ||
|
||
namespace animatedkeyboard { | ||
|
||
class AnimatedKeyBoard { | ||
private: | ||
std::atomic<bool> _execute; | ||
std::thread _thd; | ||
|
||
public: | ||
AnimatedKeyBoard(); | ||
~AnimatedKeyBoard(); | ||
void stop(); | ||
void start(int interval, std::function<void(void)> func); | ||
bool is_running() const noexcept; | ||
}; | ||
|
||
} // namespace animatedkeyboard | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.