You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.cpp 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "MainWindow.h"
  2. #include <vector>
  3. #include <QTimer>
  4. #include <QString>
  5. #include <string>
  6. #include <QDebug>
  7. MainWindow::MainWindow(QWidget *parent)
  8. : QMainWindow(parent)
  9. {
  10. tabWidget = new QTabWidget(this);
  11. pianoKeyBoard = new PianoKeyBoard(-350, 175, 700, 500, this);
  12. circleOfFifths = new CircleOfFifths(-250, 0, 500, 500, this);
  13. scene_Demo = new QGraphicsScene(-250,0,500,500, this);
  14. gV_Keyboard = new QGraphicsView(pianoKeyBoard, tabWidget);
  15. gV_CircleOfFifths = new QGraphicsView(circleOfFifths, tabWidget);
  16. gV_Demo = new QGraphicsView(scene_Demo, tabWidget);
  17. midiLog = new QPlainTextEdit();
  18. tabWidget->addTab(gV_Keyboard, "Keyboard");
  19. tabWidget->addTab(gV_CircleOfFifths, "Circle of Fifths");
  20. tabWidget->addTab(gV_Demo, "Lightshow Demonstration");
  21. tabWidget->addTab(midiLog, "Midi Messages Log");
  22. setCentralWidget(tabWidget);
  23. midiPiano = new MidiListener;
  24. midiPiano->moveToThread(&midiThread);
  25. connect(this, &MainWindow::stopMidi, midiPiano, &MidiListener::stop);
  26. // Wenn THIS das signal "startMidiListener" abgibt, wird Slot midiPiano->start ausgeführt
  27. connect(this, &MainWindow::startMidiListener, midiPiano, &MidiListener::start);
  28. connect(this, &MainWindow::nextMidiMessage, midiPiano, &MidiListener::listen);
  29. // Wenn midiPiano das signal "newMidiMessage" abgibt, wird this.handlemidimessage ausgeführt
  30. connect(midiPiano, &MidiListener::newMidiMessage, this, &MainWindow::handleMidiMessage);
  31. midiThread.start();
  32. emit startMidiListener();
  33. }
  34. void MainWindow::lightShowDemonstration(int b1, int b2, int b3)
  35. {
  36. if(b1==0x90)
  37. {
  38. if(b2>108 || b2<21) return; //no valid piano-key
  39. scene_Demo->setBackgroundBrush(colorScale.getToneByKeyboardPosition(b2)->getColor());
  40. }
  41. else if(b1==0x80)
  42. {
  43. if(b2>108 || b2<21) return; //no valid piano key
  44. if(scene_Demo->backgroundBrush().color() == colorScale.getToneByKeyboardPosition(b2)->getColor()) //only reset color if current color still is same tone
  45. scene_Demo->setBackgroundBrush(Qt::white);
  46. }
  47. }
  48. void MainWindow::handleMidiMessage(int b1, int b2, int b3){
  49. if(b1 != 0)
  50. {
  51. midiLog->appendPlainText(QString::asprintf("Byte 1: %x, Byte 2: %x, Byte 3: %x", b1, b2, b3));
  52. lightShowDemonstration(b1, b2, b3);
  53. }
  54. midiThread.msleep(10);
  55. emit nextMidiMessage();
  56. }
  57. MainWindow::~MainWindow()
  58. {
  59. emit stopMidi();
  60. midiThread.quit();
  61. midiThread.wait();
  62. }