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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. MidiProbe * probe = new MidiProbe();
  33. emit startMidiListener(probe->getPort());
  34. }
  35. void MainWindow::lightShowDemonstration(int b1, int b2, int b3)
  36. {
  37. if(b1==0x90)
  38. {
  39. if(b2>108 || b2<21) return; //no valid piano-key
  40. scene_Demo->setBackgroundBrush(colorScale.getToneByKeyboardPosition(b2)->getColor());
  41. }
  42. else if(b1==0x80)
  43. {
  44. if(b2>108 || b2<21) return; //no valid piano key
  45. if(scene_Demo->backgroundBrush().color() == colorScale.getToneByKeyboardPosition(b2)->getColor()) //only reset color if current color still is same tone
  46. scene_Demo->setBackgroundBrush(Qt::white);
  47. }
  48. }
  49. void MainWindow::handleMidiMessage(int b1, int b2, int b3){
  50. if(b1 != 0)
  51. {
  52. midiLog->appendPlainText(QString::asprintf("Byte 1: %x, Byte 2: %x, Byte 3: %x", b1, b2, b3));
  53. lightShowDemonstration(b1, b2, b3);
  54. }
  55. midiThread.msleep(10);
  56. emit nextMidiMessage();
  57. }
  58. MainWindow::~MainWindow()
  59. {
  60. emit stopMidi();
  61. midiThread.quit();
  62. midiThread.wait();
  63. }