diff --git a/extras/bad-apple.mp3 b/extras/bad-apple.wav similarity index 99% rename from extras/bad-apple.mp3 rename to extras/bad-apple.wav index c3e322b55e9bc7081e3c1aa8d92ba130078224d7..c62062c90a33381008535676c6b68e9a8092554a 100644 Binary files a/extras/bad-apple.mp3 and b/extras/bad-apple.wav differ diff --git a/src/interface.cpp b/src/interface.cpp index 99868c9f273aa347fb86f316c8b4283a588c0308..82368359f2eaeed9c45f7b6d5b5c021cc776ff4a 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -22,10 +22,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) - , ui(new Ui::MainWindow) - , simulation() - , timer(new QTimer(this)) - , m_customizing(false) + , ui(new Ui::MainWindow) + , simulation() + , timer(new QTimer(this)) + , m_customizing(false) { ui->setupUi(this); @@ -40,30 +40,30 @@ MainWindow::MainWindow(QWidget *parent) connect(ui->struct_library, &StructureLibraryView::structure_copied, this, &MainWindow::copy_structure_clicked); connect(ui->grid_view, &GridView::zoom_changed, ui->struct_library, &StructureLibraryView::update_cell_pixel_size); connect(ui->statesSettingsButton, &QPushButton::clicked, this, [this] - { - ColorLabel* dialog = new ColorLabel(simulation.getAlphabet(), this); - if (dialog->exec()) - { - ui_update_alphabet(dialog->getAlphabet()); - } - }); + { + ColorLabel* dialog = new ColorLabel(simulation.getAlphabet(), this); + if (dialog->exec()) + { + ui_update_alphabet(dialog->getAlphabet()); + } + }); connect(ui->transition_list, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int) - { update_transition_settings(); }); + { update_transition_settings(); }); connect(ui->action_bad_apple, &QAction::triggered, this, &MainWindow::play_bad_apple); connect(ui->action_propos_de_Cellulut, &QAction::triggered, this, [this](bool) - { - QMessageBox::about(this, "À propos de Cellulut", - "Projet de C++ réalisé dans le cadre de l'UV LO21 de l'UTC.\n\n" + { + QMessageBox::about(this, "À propos de Cellulut", + "Projet de C++ réalisé dans le cadre de l'UV LO21 de l'UTC.\n\n" "Contributeurs : Anthony Noir, Eugène Pin, Merwane Bouri, Arthur Detree, Yann Boucher"); - }); + }); connect(ui->action_propos_de_Qt, &QAction::triggered, this, [this](bool) - { - QMessageBox::aboutQt(this, "À propos de Qt"); - }); + { + QMessageBox::aboutQt(this, "À propos de Qt"); + }); connect(ui->actionCharger_depuis_une_image, &QAction::triggered, this, [this](bool) - { - load_from_image(); - }); + { + load_from_image(); + }); ui->struct_library->update_cell_pixel_size(ui->grid_view->cell_screen_size()); @@ -632,6 +632,10 @@ QJsonObject MainWindow::default_configuration() const return doc.object(); } +#ifdef _WIN32 +#include <windows.h> +#endif + void MainWindow::play_bad_apple() { static QJsonArray bad_apple_frame_list; @@ -657,39 +661,47 @@ void MainWindow::play_bad_apple() if (!bad_apple_connected) { bad_apple_timer.callOnTimeout([this] - { + { - unsigned frame_idx = bad_apple_elapsed.elapsed()/(1000.f/30); - if ((int)frame_idx >= bad_apple_frame_list.size()) - { - bad_apple_timer.stop(); - return; - } + unsigned frame_idx = bad_apple_elapsed.elapsed()/(1000.f/30); + if ((int)frame_idx >= bad_apple_frame_list.size()) + { + bad_apple_timer.stop(); + return; + } - Grid grid(120, 160); + Grid grid(120, 160); - QJsonObject frame = bad_apple_frame_list[frame_idx].toObject(); + QJsonObject frame = bad_apple_frame_list[frame_idx].toObject(); - Coord origin; - origin.x = frame.value("left").toInt(); - origin.y = frame.value("top").toInt(); + Coord origin; + origin.x = frame.value("left").toInt(); + origin.y = frame.value("top").toInt(); - RLEStructureReader reader(frame.value("data").toString().toStdString()); - Structure s = reader.read_structure(); - s.top_left = origin; + RLEStructureReader reader(frame.value("data").toString().toStdString()); + Structure s = reader.read_structure(); + s.top_left = origin; - for (auto cell : s) - { - grid.set_cell(cell.first + s.top_left, cell.second); - } + for (auto cell : s) + { + grid.set_cell(cell.first + s.top_left, cell.second); + } - ui->grid_view->copy_grid(grid); - }); + ui->grid_view->copy_grid(grid); + }); } //bad_apple_player.setMedia(QUrl::fromLocalFile("bad-apple.mp3")); //bad_apple_player.play(); ; + +#ifdef _WIN32 + PlaySound(TEXT("extras/bad-apple.wav"), GetModuleHandle(NULL), SND_FILENAME | SND_ASYNC); + Sleep(1300); // delay for the sound to load +#elif + QMessageBox::information(this, "", "Music functionnality is only available on Windows"); +#endif + bad_apple_elapsed.start(); bad_apple_timer.start(24); statusBar()->showMessage("Original : \"Bad Apple!!\" feat. Nomico by Alstroemeria Records", 60000); diff --git a/src/src.pro b/src/src.pro index d80df8915344ea2bac3db56846a38d50f1a62193..ee5b0d1b1254146ac67c6baa7ac5c4d9d3b5e6b3 100644 --- a/src/src.pro +++ b/src/src.pro @@ -96,6 +96,10 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target +win32 { +LIBS += -lwinmm +} + CONFIG(debug, debug|release) { DEBUG_OR_RELEASE = debug } else {