hard_cast to fix type punning warnings
parent
4db24fb188
commit
3137c5e699
|
@ -28,6 +28,7 @@ using namespace Xybrid::UI;
|
|||
#include "ui/patchboard/nodeuiscene.h"
|
||||
#include "uisocket.h"
|
||||
|
||||
#include "util/ext.h"
|
||||
#include "util/strings.h"
|
||||
|
||||
#include <cmath>
|
||||
|
@ -66,7 +67,7 @@ void BeatPad::init() {
|
|||
addPort(Port::Output, Port::Audio, 0);
|
||||
|
||||
core.onNoteOn = [this](Note& note) {
|
||||
auto& data = *reinterpret_cast<NoteData*>(¬e.scratch);
|
||||
auto& data = *hard_cast<NoteData*>(¬e.scratch);
|
||||
new (&data) NoteData(); // construct in-place
|
||||
|
||||
// look up config for note
|
||||
|
@ -79,7 +80,7 @@ void BeatPad::init() {
|
|||
};
|
||||
|
||||
core.onDeleteNote = [](Note& note) {
|
||||
auto& data = *reinterpret_cast<NoteData*>(¬e.scratch);
|
||||
auto& data = *hard_cast<NoteData*>(¬e.scratch);
|
||||
data.~NoteData(); // destroy
|
||||
};
|
||||
|
||||
|
@ -89,7 +90,7 @@ void BeatPad::init() {
|
|||
};*/
|
||||
|
||||
core.processNote = [this](Note& note, AudioPort* p) {
|
||||
auto& data = *reinterpret_cast<NoteData*>(¬e.scratch);
|
||||
auto& data = *hard_cast<NoteData*>(¬e.scratch);
|
||||
if (!data.config) return core.deleteNote(note);
|
||||
auto smp = data.config->smp.lock();
|
||||
if (!smp) return core.deleteNote(note);
|
||||
|
|
|
@ -28,6 +28,7 @@ using namespace Xybrid::UI;
|
|||
#include "ui/patchboard/nodeuiscene.h"
|
||||
#include "uisocket.h"
|
||||
|
||||
#include "util/ext.h"
|
||||
#include "util/strings.h"
|
||||
|
||||
#include <cmath>
|
||||
|
@ -64,19 +65,19 @@ void Capaxitor::init() {
|
|||
addPort(Port::Output, Port::Audio, 0);
|
||||
|
||||
core.onNoteOn = [this](Note& note) {
|
||||
auto& data = *reinterpret_cast<NoteData*>(¬e.scratch);
|
||||
auto& data = *hard_cast<NoteData*>(¬e.scratch);
|
||||
new (&data) NoteData(); // construct in-place
|
||||
|
||||
note.adsr = adsr;
|
||||
};
|
||||
|
||||
core.onDeleteNote = [](Note& note) {
|
||||
auto& data = *reinterpret_cast<NoteData*>(¬e.scratch);
|
||||
auto& data = *hard_cast<NoteData*>(¬e.scratch);
|
||||
data.~NoteData(); // destroy
|
||||
};
|
||||
|
||||
core.processNote = [this](Note& note, AudioPort* p) {
|
||||
auto& data = *reinterpret_cast<NoteData*>(¬e.scratch);
|
||||
auto& data = *hard_cast<NoteData*>(¬e.scratch);
|
||||
auto smp = this->smp.lock();
|
||||
if (!smp) return core.deleteNote(note);
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
// miscellaneous "language extensions"
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template<typename TO, typename FROM> inline constexpr TO hard_cast(FROM f) {
|
||||
static_assert(std::is_pointer_v<TO> && std::is_pointer_v<FROM>);
|
||||
return reinterpret_cast<TO>( reinterpret_cast<void*>(f) );
|
||||
}
|
|
@ -22,6 +22,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
|||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00
|
||||
|
||||
DISTFILES += ../.astylerc
|
||||
|
||||
|
|
Loading…
Reference in New Issue