File tree 8 files changed +125
-1
lines changed
8 files changed +125
-1
lines changed Original file line number Diff line number Diff line change
1
+ .vscode
2
+ build
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.12)
2
+
3
+ # Set the project name and version
4
+ project (Piano VERSION 1.0.0)
5
+
6
+ # Set C++ standard
7
+ set (CMAKE_CXX_STANDARD 11)
8
+ set (CMAKE_CXX_EXTENSIONS OFF )
9
+ set (CMAKE_CXX_STANDARD_REQUIRED TRUE )
10
+
11
+ # Enable debug symbols by default
12
+ if (NOT CMAKE_BUILD_TYPE )
13
+ set (CMAKE_BUILD_TYPE Debug
14
+ CACHE STRING
15
+ "Choose the type of build (Debug or Release)" FORCE)
16
+ endif ()
17
+
18
+ # Export compile commands for completion engines (optional)
19
+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
20
+
21
+ # Set option to control setting the resource path variable
22
+ option (USE_INSTALL_RESOURCE_PATH "Set resource path to install location" OFF )
23
+
24
+ # Find SFML shared libraries
25
+ find_package (SFML 2.5 COMPONENTS system window graphics audio network REQUIRED)
26
+
27
+ # Including custom headers
28
+ include_directories (./include )
29
+
30
+ # Compile executable
31
+ add_executable (Piano ./src/main.cpp ./src/piano.cpp)
32
+
33
+ # Link executable to required SFML modules
34
+ target_link_libraries (Piano sfml-graphics sfml-audio)
Original file line number Diff line number Diff line change 1
- # Piano
1
+ # Piano
2
+
3
+ ## Setup
4
+ My setup was on Ubuntu 20.04. To download SFML, run:
5
+
6
+ ``` sh
7
+ sudo apt update
8
+ sudo apt upgrade
9
+ sudo apt install libsfml-dev
10
+ ```
11
+
12
+ Now, in order to run the application, navigate into this directory and run the following commands:
13
+ ``` sh
14
+ chmod +x ./run.sh
15
+ ./run.sh
16
+ ```
Original file line number Diff line number Diff line change
1
+ #ifndef CONFIG_H_INCLUDED
2
+ #define CONFIG_H_INCLUDED
3
+
4
+ const int WINDOW_WIDTH = 1200 ;
5
+ const int WINDOW_HEIGHT = 600 ;
6
+
7
+ #endif // CONFIG_H_INCLUDED
Original file line number Diff line number Diff line change
1
+ #ifndef PIANO_H_INCLUDED
2
+ #define PIANO_H_INCLUDED
3
+
4
+ #include < SFML/Graphics.hpp>
5
+
6
+ #include " config.h"
7
+
8
+ class Piano
9
+ {
10
+ private:
11
+ sf::RenderWindow* window;
12
+ sf::Event event;
13
+
14
+ public:
15
+ Piano ();
16
+ ~Piano ();
17
+
18
+ void play ();
19
+ void display ();
20
+ };
21
+
22
+ #endif // PIANO_H_INCLUDED
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ if [ ! -d " ./build" ]; then
4
+ mkdir build
5
+ fi
6
+
7
+ cd build
8
+ cmake ..
9
+ make
10
+
11
+ ./Piano
Original file line number Diff line number Diff line change
1
+ #include " piano.h"
2
+
3
+ int main (int argc, char ** argv){
4
+
5
+ Piano piano;
6
+ piano.play ();
7
+
8
+ return EXIT_SUCCESS;
9
+ }
Original file line number Diff line number Diff line change
1
+ #include " piano.h"
2
+
3
+ Piano::Piano (){
4
+ window = new sf::RenderWindow (sf::VideoMode (WINDOW_WIDTH, WINDOW_HEIGHT), " Piano" );
5
+ window->setFramerateLimit (10 );
6
+ }
7
+
8
+ Piano::~Piano (){
9
+ delete window;
10
+ }
11
+
12
+ void Piano::play (){
13
+ while (window->isOpen ()){
14
+ window->pollEvent (event);
15
+
16
+ if (event.type == sf::Event::Closed)
17
+ window->close ();
18
+ }
19
+ }
20
+
21
+ void Piano::display (){
22
+ window->clear ();
23
+ window->display ();
24
+ }
You can’t perform that action at this time.
0 commit comments