From e2d018a46d0cbe6e9b641d554f7074af0784b264 Mon Sep 17 00:00:00 2001 From: Nicoleta Ciausu Date: Thu, 16 Apr 2020 04:05:29 +0300 Subject: [PATCH] Update README.md --- README.md | 78 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e704528..9ebe2ae 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,47 @@ catch (int errCode) { #include #include ``` -๐ŸŽน Lambda expressions\ -๐ŸŽน Templates\ -๐ŸŽน Smart pointers - minim 1 tip / proiect\ -๐ŸŽน Design patterns - minim 2 +๐ŸŽน Lambda expressions ๐Ÿ—น +```cpp +// MainWindow.cpp +auto getKeyPressed = [=]() { + return piano->findKeyPressed(settings.getKbKeys()[std::to_string(event.key.code)]); +}; + +//usage +if (event.type == sf::Event::KeyPressed) +{ + if (settings.getKbKeys().contains(std::to_string(event.key.code))) + { + + activeKey = getKeyPressed(); + Recorder::log("down", activeKey->getId()); + // ... + } +} +``` +๐ŸŽน Templates ๐Ÿ—น +```cpp +// MainWindow.cpp + +//// Definiton //// +template +void MainWindow::checkPressed(T &obj) +{ + if (obj.getSprite().getGlobalBounds().contains(mapPixelToCoords(sf::Mouse::getPosition((*this))))) + obj.press(true); +} +``` +๐ŸŽน Smart pointers - minim 1 tip / proiect +```cpp +// Piano.cpp + +static std::shared_ptr instance; +std::vector> piano; + +... and many more! +``` +๐ŸŽน Design patterns - minim 2 ๐Ÿ—น #### Singleton ๐Ÿ—น ```cpp @@ -86,12 +123,37 @@ public: } ``` -#### Facade? +#### Facade ๐Ÿ—น ```cpp -// Coming soon! +// Recorder.h - facade that hides all recording logic. +class Recorder { + static json songData; + static sf::Clock clock; + static bool recording; + public: + Recorder(); + static void start(); + static void stop(); + static void save(); + static void log(std::string type, int noteId); + static void play(); + static void load(std::string path); + static bool isRecording(); +}; +``` +๐ŸŽน Features of C++17/20 (constexpr, consteval, constinit, fold expressions, init statement for if/switch, etc) ๐Ÿ—น +```cpp +//// Init statement for if (C++17) //// +if (double seconds = clock.getElapsedTime().asMilliseconds(); seconds < 100) +{ + //Atenuare sunet :) onKeyReleased + c = std::lerp(100, 0, seconds / 100.0); + //std::cout << seconds << " " << c << std::endl; + sound.setVolume(c); + if (c <= 5.0) + break; +} ``` -๐ŸŽน Features of C++17/20 (constexpr, consteval, constinit, fold expressions, init statement for if/switch, etc) (minim 1 / proiect) - **Opศ›ional => Bonus:**\ ๐ŸŽน Move semantics\ ๐ŸŽน Multithreading (la echipe de 3-4 oameni)\