Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
core.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //============================================================================
21 // Core
22 //============================================================================
23 
24 #include "core.h"
25 #include "messages/message.h"
31 #include <assert.h>
32 
33 //-----------------------------------------------------------------------------
34 // Core constructor
35 //-----------------------------------------------------------------------------
36 
44 
46  AudioRecorderAdapter *recorderAdapter,
47  AudioPlayerAdapter *playerAdapter,
48  Log *log)
49  : mInitialized(false), // Initially not initialized
50  mProjectManager(projectManager),
51  mRecorderAdapter(recorderAdapter),
52  mPlayerAdapter(playerAdapter),
53  mSoundGenerator (playerAdapter),
54  mRecordingManager (recorderAdapter),
55  mSignalAnalyzer(recorderAdapter)
56 {
58  EptAssert(log, "A log has to be specified during creation of the core");
59  LogI("Core created");
60 }
61 
62 
63 //-----------------------------------------------------------------------------
64 // Destructor
65 //-----------------------------------------------------------------------------
66 
70 
72 {
73  stop();
74  exit(); // just to be sure
75  LogI("Core denstroyed");
76 }
77 
78 
79 
80 //-----------------------------------------------------------------------------
81 // Core initialization procedure
82 //-----------------------------------------------------------------------------
83 
94 
96 {
97  EptAssert(initAdapter, "At least the default adapter has to be provided");
98 
99  if (mInitialized) return; // If already initialized return
100 
101  initAdapter->create(); // Open initialization message mox
102 
103  initAdapter->updateProgress (0); // Initialize recorder
105 
106  initAdapter->updateProgress (11); // Initialize player
107  mPlayerAdapter->init();
108 
109  initAdapter->updateProgress (22); // Start the player, so that the startup sound is played
111 
112  initAdapter->updateProgress (33); // Initialize the signal analyzer
114 
115  initAdapter->updateProgress (50); // Initialize the sound generator
117 
118  initAdapter->updateProgress (65); // Initialize the recording manager
120 
121  initAdapter->updateProgress (75); // Initialze the MIDI system
122  mMidi->init();
123 
124  initAdapter->updateProgress (87); // Open the default MIDI port
125  std::stringstream ss;
126  ss << "There are " << mMidi->GetNumberOfPorts() << " connected Midi devices:" << std::endl << mMidi->GetPortNames();
127  LogI("%s", ss.str().c_str());
128  mMidi->OpenPort();
129 
130  initAdapter->updateProgress (100);
131 
132  mInitialized = true; // set initialization flag and
133  initAdapter->destroy(); // remove the init message box
134 }
135 
136 
137 
138 //-----------------------------------------------------------------------------
139 // Exit
140 //-----------------------------------------------------------------------------
141 
145 
147 {
148  if (not mInitialized) return;
149  stop();
150  mMidi->exit();
154  mPlayerAdapter->exit();
157 
158  mInitialized = false;
159 }
160 
161 
162 //-----------------------------------------------------------------------------
163 // Start the core
164 //-----------------------------------------------------------------------------
165 
171 
173 {
174  LogI("Starting the core");
177 }
178 
179 
180 
181 //-----------------------------------------------------------------------------
182 // Stop the core
183 //-----------------------------------------------------------------------------
184 
190 
192 {
195  mPlayerAdapter->stop();
196 }
static CalculationManager & getSingleton()
Abstract adapter class for recording audio signals.
virtual void start()=0
Start/restart the audio device.
AudioRecorderAdapter * mRecorderAdapter
Definition: core.h:73
virtual std::shared_ptr< MidiAdapter > createMidiAdapter() const
void stop()
Stop the core.
Definition: core.cpp:191
virtual void destroy()=0
Destroy the initialization dialog box.
void start()
Start the core.
Definition: core.cpp:172
void init(CoreInitialisationAdapter *initAdapter)
Core initialization.
Definition: core.cpp:95
RecordingManager mRecordingManager
Definition: core.h:76
void exit()
Synthesizer shutdown.
virtual void updateProgress(int percentage)=0
Show the current progress as a progress bar in the initialization message box.
virtual void exit() override
Destroy the audio device.
AudioPlayerAdapter * mPlayerAdapter
Definition: core.h:74
virtual void stop()=0
Stop the audio device.
Core initialization adapter (singleton class).
virtual void stop() override
Stop the thread.
#define LogI(...)
Definition: log.h:50
Core(ProjectManagerAdapter *projectManager, AudioRecorderAdapter *recorderAdapter, AudioPlayerAdapter *playerAdapter, Log *log=new Log())
Core constructor.
Definition: core.cpp:45
void stop()
Stop the calculation thread.
void exit()
Thus function calls exit() of all components that were initialized.
Definition: core.cpp:146
void init()
Initialize (no functionality)
#define EptAssert(a, b)
Definition: eptexception.h:47
virtual void exit()=0
Destroy the audio device.
virtual void create()=0
Create the initialization dialog box.
bool mInitialized
Definition: core.h:71
virtual void init()=0
Inizialize the audio device.
Definition: log.h:67
SignalAnalyzer mSignalAnalyzer
Definition: core.h:77
~Core()
Core destructor, calls stop and exit.
Definition: core.cpp:71
SoundGenerator mSoundGenerator
Definition: core.h:75
Abstract adapter class for PCM-based audio output drivers.
static PlatformToolsCore * getSingleton()
Project manager adapter class.
void init()
Initializes the SignalAnalyzer and its components.
std::shared_ptr< MidiAdapter > mMidi
Definition: core.h:79