123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #include "MainWindow.h"
- #include <vector>
- #include <QTimer>
-
- #include <QString>
- #include <string>
- #include <QDebug>
-
- 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();
- MidiProbe * probe = new MidiProbe();
- emit startMidiListener(probe->getPort());
-
- }
-
- 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();
- }
|