Just Intonation  Version 1.3.0 (18)
Explore scale-independent dynamically adapting tuning in just intonation
instrument.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2016-2017 Karolin Stange, Christoph Wick, and Haye Hinrichsen
3  *
4  * This file is part of JustIntonation.
5  *
6  * JustIntonation 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  * JustIntonation 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
14  * for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with JustIntonation. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // Class describing an instrument
22 //=============================================================================
23 
24 #include "instrument.h"
25 
26 #include <QDebug>
27 #include <QFile>
28 
29 #define STATUS if (Voice::mVerbosity >= 4) qDebug() << "Instrument:"
30 #define MESSAGE if (Voice::mVerbosity >= 3) qDebug() << "Instrument:"
31 #define WARNING if (Voice::mVerbosity >= 2) qWarning()<<"Instrument: WARNING:"
32 #define ERROR if (Voice::mVerbosity >= 1) qCritical() << "Instrument: ERROR:"
33 
34 
36  : ThreadBase()
37  , mVoice()
38  , mFileName()
39  , mLoading(false)
40  , mLoaded(false)
41 {
42  setThreadName("Instrument");
43 }
44 
45 
46 //----------------------------------------------------------------------------
47 // Load or generate a voice
48 //----------------------------------------------------------------------------
53 
55 {
56  cancelLoading();
57  return ThreadBase::stop();
58 }
59 
60 
61 //----------------------------------------------------------------------------
62 // Load or generate a voice
63 //----------------------------------------------------------------------------
71 
72 void Instrument::loadInstrument (QString path)
73 {
74  MESSAGE << "Loading" << path;
75  mLoading = true;
76  mFileName = path;
77  if (mFileName.size()==0)
78  {
79  STATUS << "Generate artificial sound";
80  emit showProgressBar(tr("Generating artificial sound."));
82  emit hideProgressBar();
83  }
84  else
85  {
86  STATUS << "Load instrument" << mFileName;
87  QFile file(mFileName);
88  if (not file.open(QIODevice::ReadOnly))
89  {
90  ERROR << "Cannot open file" << mFileName;
91  emit signalLoadingFinished(false);
92  mLoading = false;
93  return;
94  }
95  mLoaded = false;
96  emit showProgressBar(tr("Loading instrument. Please wait..."));
97  mLoaded = mVoice.read(file);
98  emit hideProgressBar();
99  if (mLoaded) { MESSAGE << "File successfully read"; }
100  else { WARNING << "Could not read file" << mFileName; }
102  }
103  mLoading = false;
104 }
105 
Universal base class for threaded modules.
Definition: threadbase.h:60
void generateArtificialSound(int samplerate)
Definition: voice.cpp:58
bool mLoaded
Flag indicating that an instrument has been loaded.
Definition: instrument.h:61
void hideProgressBar()
#define WARNING
Definition: instrument.cpp:31
void cancelLoading()
Definition: instrument.h:50
#define STATUS
Definition: instrument.cpp:29
bool stop() override final
Stop the instrument thread.
Definition: instrument.cpp:54
void loadInstrument(QString path)
Load or generate an instrument (voice)
Definition: instrument.cpp:72
bool read(QIODevice &iodevice)
Definition: voice.cpp:117
bool mLoading
Flag indicating that an instrument is being loaded.
Definition: instrument.h:60
void showProgressBar(QVariant)
#define MESSAGE
Definition: instrument.cpp:30
#define ERROR
Definition: instrument.cpp:32
void setThreadName(const QString name)
Set thread name (Linux only)
Definition: threadbase.cpp:121
QString mFileName
The file name from where the file is loaded.
Definition: instrument.h:59
virtual bool stop()
Stop the thread.
Definition: threadbase.cpp:152
void signalLoadingFinished(bool)
Voice mVoice
The set of all samples.
Definition: instrument.h:58