From b574fcd537997381b47216551d8fe38dfbf971c1 Mon Sep 17 00:00:00 2001 From: Lars Mewes Date: Fri, 8 Oct 2021 11:20:13 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9E=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColorScale.h | 31 +++ Lichtklavier.pro | 42 ++++ Lichtklavier.pro.user | 452 ++++++++++++++++++++++++++++++++++++++++++ MainWindow.cpp | 77 +++++++ main.cpp | 13 ++ 5 files changed, 615 insertions(+) create mode 100644 ColorScale.h create mode 100644 Lichtklavier.pro create mode 100644 Lichtklavier.pro.user create mode 100644 MainWindow.cpp create mode 100644 main.cpp diff --git a/ColorScale.h b/ColorScale.h new file mode 100644 index 0000000..212e795 --- /dev/null +++ b/ColorScale.h @@ -0,0 +1,31 @@ +/* COLORSCALE_H + * CLASS DECLARATION + * + * CHANGLOG: + * NAME: | CHANGES: | DATE: | + * Mewes, Lars | Neuerstellung | 24.09.2021 | + * | | | + * | | | + * | | | + * + * DESCRIPTION: + * Diese Klasse beinhaltet sämtliche Töne einer Oktave, die mithilfe von getter-setter-Funktionen genutzt werden können. + * + * TO-DOs: + * + * + */ + +#pragma once +#include "Tone.h" + + +class ColorScale{ + Tone allTones[12]; +public: + Tone * getToneByName(QString name); + Tone * getToneByKeyboardPosition(int pos); + void setToneColor(Tone * tone, QColor color); + ColorScale(); + +}; diff --git a/Lichtklavier.pro b/Lichtklavier.pro new file mode 100644 index 0000000..39a7cb7 --- /dev/null +++ b/Lichtklavier.pro @@ -0,0 +1,42 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +DEFINES += __LINUX_ALSA__ #ADDED BY L.Mewes 28.09.2021 +LIBS += -lasound # +LIBS += -lpthread # + # + +SOURCES += \ + CircleElement.cpp \ + CircleOfFifths.cpp \ + ColorScale.cpp \ + MainWindow.cpp \ + MidiListener.cpp \ + PianoKey.cpp \ + PianoKeyBoard.cpp \ + RtMidi.cpp \ + Tone.cpp \ + main.cpp + +HEADERS += \ + CircleElement.h \ + CircleOfFifths.h \ + ColorScale.h \ + MainWindow.h \ + MidiListener.h \ + PianoKey.h \ + PianoKeyBoard.h \ + RtMidi.h \ + Tone.h + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/Lichtklavier.pro.user b/Lichtklavier.pro.user new file mode 100644 index 0000000..7ddef0c --- /dev/null +++ b/Lichtklavier.pro.user @@ -0,0 +1,452 @@ + + + + + + EnvironmentId + {ba989da4-3412-4036-b21a-76cd46a17f76} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.1.3 GCC 64bit + Desktop Qt 6.1.3 GCC 64bit + qt.qt6.613.gcc_64_kit + 0 + 0 + 0 + + 0 + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Debug + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Release + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Profile + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deployment + Deployment + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/lars/Lichtklavier_Tabs/Lichtklavier.pro + /home/lars/Lichtklavier_Tabs/Lichtklavier.pro + false + true + true + false + true + /home/lars/build-Lichtklavier-Desktop_Qt_6_1_3_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 + + GenericLinuxOsType + pi + pi + {37e0af0d-d84f-47fb-a4e8-b572586c1c08} + 0 + 0 + 0 + + 0 + /home/lars/build-Lichtklavier-pi-Debug + /home/lars/build-Lichtklavier-pi-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/lars/build-Lichtklavier-pi-Release + /home/lars/build-Lichtklavier-pi-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + 0 + /home/lars/build-Lichtklavier-pi-Profile + /home/lars/build-Lichtklavier-pi-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + 3 + + + + true + RemoteLinux.CheckForFreeDiskSpaceStep + + + + + / + 5242880 + + + + + true + RemoteLinux.KillAppStep + + + + + + + + + true + RemoteLinux.DirectUploadStep + + + + + + + + 3 + Deployment + Deployment + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + DeployToGenericLinux + + 1 + + true + true + true + + 1 + + Lichtklavier (on %{Device:Name}) + RemoteLinuxRunConfiguration:/home/lars/Lichtklavier_Tabs/Lichtklavier.pro + /home/lars/Lichtklavier_Tabs/Lichtklavier.pro + 1 + false + true + false + true + :0 + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/MainWindow.cpp b/MainWindow.cpp new file mode 100644 index 0000000..bf43e96 --- /dev/null +++ b/MainWindow.cpp @@ -0,0 +1,77 @@ +#include "MainWindow.h" +#include +#include + +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + tabWidget = new QTabWidget(this); + + pianoKeyBoard = new PianoKeyBoard(-350, 175, 700, 500, this); + circleOfFifths = new CircleOfFifths(-250, 0, 500, 500, this); + scene_Demo = new QGraphicsScene(-250,0,500,500, this); + + gV_Keyboard = new QGraphicsView(pianoKeyBoard, tabWidget); + gV_CircleOfFifths = new QGraphicsView(circleOfFifths, tabWidget); + gV_Demo = new QGraphicsView(scene_Demo, tabWidget); + midiLog = new QPlainTextEdit(); + + + tabWidget->addTab(gV_Keyboard, "Keyboard"); + tabWidget->addTab(gV_CircleOfFifths, "Circle of Fifths"); + tabWidget->addTab(gV_Demo, "Lightshow Demonstration"); + tabWidget->addTab(midiLog, "Midi Messages Log"); + + setCentralWidget(tabWidget); + midiPiano = new MidiListener; + + midiPiano->moveToThread(&midiThread); + + connect(this, &MainWindow::stopMidi, midiPiano, &MidiListener::stop); + // Wenn THIS das signal "startMidiListener" abgibt, wird Slot midiPiano->start ausgeführt + connect(this, &MainWindow::startMidiListener, midiPiano, &MidiListener::start); + connect(this, &MainWindow::nextMidiMessage, midiPiano, &MidiListener::listen); + // Wenn midiPiano das signal "newMidiMessage" abgibt, wird this.handlemidimessage ausgeführt + connect(midiPiano, &MidiListener::newMidiMessage, this, &MainWindow::handleMidiMessage); + midiThread.start(); + emit startMidiListener(); + +} + +void MainWindow::lightShowDemonstration(int b1, int b2, int b3) +{ + if(b1==0x90) + { + if(b2>108 || b2<21) return; //no valid piano-key + scene_Demo->setBackgroundBrush(colorScale.getToneByKeyboardPosition(b2)->getColor()); + } + else if(b1==0x80) + { + if(b2>108 || b2<21) return; //no valid piano key + if(scene_Demo->backgroundBrush().color() == colorScale.getToneByKeyboardPosition(b2)->getColor()) //only reset color if current color still is same tone + scene_Demo->setBackgroundBrush(Qt::white); + } + +} + +void MainWindow::handleMidiMessage(int b1, int b2, int b3){ + if(b1 != 0) + { + midiLog->appendPlainText(QString::asprintf("Byte 1: %x, Byte 2: %x, Byte 3: %x", b1, b2, b3)); + lightShowDemonstration(b1, b2, b3); + } + midiThread.msleep(10); + emit nextMidiMessage(); +} + +MainWindow::~MainWindow() +{ + emit stopMidi(); + midiThread.quit(); + midiThread.wait(); +} + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c338757 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include "MainWindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + + w.show(); + + return a.exec(); +}