Skip to content

Commit

Permalink
Some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Oct 16, 2024
1 parent 9217e4b commit c31e2f1
Show file tree
Hide file tree
Showing 9 changed files with 518 additions and 443 deletions.
71 changes: 71 additions & 0 deletions src/AnimatedKeyBoard.cpp
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

56 changes: 56 additions & 0 deletions src/AnimatedKeyBoard.h
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
9 changes: 9 additions & 0 deletions src/CustomDrawings.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@

#ifndef CUSTOMDRAWINGS_H
#define CUSTOMDRAWINGS_H

/****************************************************************
** class CustomDrawings
**
** drawing routines from Mamba - Virtual Midi Keyboard
**
*/

namespace midikeyboard {

class CustomDrawings {
public:

Expand Down
3 changes: 2 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ endif
`pkg-config --cflags jack cairo x11 sigc++-2.0 liblo smf fluidsynth`\
-DVERSION=\"$(VER)\"
# invoke build files
OBJECTS = $(OLDNAME).cpp $(NAME).cpp XAlsa.cpp XJack.cpp NsmHandler.cpp XSynth.cpp MidiMapper.cpp
OBJECTS = $(NAME).cpp XAlsa.cpp XJack.cpp NsmHandler.cpp XSynth.cpp MidiMapper.cpp main.cpp \
PosixSignalHandler.cpp AnimatedKeyBoard.cpp $(OLDNAME).cpp
SOBJECTS = $(LIBSCALA_DIR)scala_kbm.cpp $(LIBSCALA_DIR)scala_scl.cpp
COBJECTS = xmkeyboard.c xcustommap.c
OBJ_FILES = $(addprefix ./$(BUILD_DIR)/,$(notdir $(OBJECTS:.cpp=.o)))
Expand Down
Loading

0 comments on commit c31e2f1

Please sign in to comment.