diff --git a/CMakeLists.txt b/CMakeLists.txt index f213cca878ab9e405a799baf2e3556b10580e984..cbe35aedd3856dc90ca4ed6002feea940506cb2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,8 +217,6 @@ add_subdirectory( packaging ) # cpack rules # Uncomment below lines if you want to build any testing executable -# add_subdirectory( tests/plugtester ) -# add_subdirectory( tests/nootini ) # add_subdirectory( tests/nootoxml ) # add_subdirectory( tests/bp ) diff --git a/tests/nootini/CMakeLists-libsndfile.txt b/tests/nootini/CMakeLists-libsndfile.txt deleted file mode 100755 index 9c01324b95bef93197b5a75ea980840f12f0d294..0000000000000000000000000000000000000000 --- a/tests/nootini/CMakeLists-libsndfile.txt +++ /dev/null @@ -1,93 +0,0 @@ -######################################################################## -# nootini - Nootka research tool for pitch detection -######################################################################## - -cmake_minimum_required(VERSION 2.8.12) - -project(nootini) - -if (CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") -endif (CMAKE_BUILD_TYPE STREQUAL "Release") - -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Svg REQUIRED) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) - -if (SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS) - set(LIBSNDFILE_FOUND TRUE) - else(SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS) - find_path(LIBSNDFILE_INCLUDE_DIR - NAMES - sndfile.h - PATHS - /usr/include - /usr/local/include - /opt/local/include - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_BINARY_DIR}/../libsndfile - ) - - find_library(LIBSNDFILE_LIBRARY - NAMES - sndfile - PATHS - /usr/lib - /usr/lib64 - /usr/local/lib - /opt/local/lib - /sw/lib - ${CMAKE_BINARY_DIR}/../libsndfile - ${CMAKE_CURRENT_SOURCE_DIR} - ) - - set(SNDFILE_INCLUDE_DIRS ${LIBSNDFILE_INCLUDE_DIR}) - set(SNDFILE_LIBRARIES ${LIBSNDFILE_LIBRARY}) - - if (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES) - set(LIBSNDFILE_FOUND TRUE) - endif (SNDFILE_INCLUDE_DIRS AND SNDFILE_LIBRARIES) - - if (LIBSNDFILE_FOUND) - message(STATUS "libsndfile was Found in:\n${SNDFILE_LIBRARIES}\nheaders are in: ${SNDFILE_INCLUDE_DIRS}") - ELSE(LIBSNDFILE_FOUND) - message(FATAL_ERROR "Could not find libsndfile\nTry call cmake with args:\n-DSNDFILE_LIBRARIES=/path_to/libSoundTouch.la(dll) -DSNDFILE_INCLUDE_DIRS=/path_to_dir_with/sndfile.h\nor put those files in build dir or source dir") - ENDIF(LIBSNDFILE_FOUND) - - ENDIF(SNDFILE_LIBRARIES AND SNDFILE_INCLUDE_DIRS) - -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../src/) - -include_directories( ../../src/libs/core ../../src/libs/sound ../../src/plugins/charts ${SNDFILE_INCLUDE_DIRS} ) - -if (${WIN32}) - include_directories(${FFTW3_INCLUDE_DIRS}) -endif(${WIN32}) - -set(NOOTINI_SRC - main.cpp - nootiniwindow.cpp - nchart.cpp - naudioloader.cpp - nootinisettings.cpp - - ../../src/plugins/charts/tchart.cpp - ../../src/plugins/charts/tabstractaxis.cpp - ../../src/plugins/charts/txaxis.cpp - ../../src/plugins/charts/tyaxis.cpp - ../../src/plugins/charts/ttiphandler.cpp - ../../src//plugins/charts/tgroupedqaunit.cpp - ../../src/plugins/settings/tvolumeslider.cpp - -) - -add_executable(nootini WIN32 ${NOOTINI_SRC}) -target_link_libraries(nootini - NootkaCore - NootkaSound - Qt5::Widgets - Qt5::Svg - ${SNDFILE_LIBRARIES} -) - diff --git a/tests/nootini/CMakeLists.txt b/tests/nootini/CMakeLists.txt deleted file mode 100755 index 8142a8e840f483060454cf339b69d27342dfdd01..0000000000000000000000000000000000000000 --- a/tests/nootini/CMakeLists.txt +++ /dev/null @@ -1,46 +0,0 @@ -######################################################################## -# nootini - Nootka research tool for pitch detection -######################################################################## - -cmake_minimum_required(VERSION 2.8.12) - -project(nootini) - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - -if (CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") -endif (CMAKE_BUILD_TYPE STREQUAL "Release") - -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Svg REQUIRED) -set(CMAKE_INCLUDE_CURRENT_DIR ON) -set(CMAKE_AUTOMOC ON) - -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../src/) - -include_directories( ../../src/libs/core ../../src/libs/score ../../src/libs/sound ../../src/plugins/charts ) -if (${WIN32}) - include_directories(${FFTW3_INCLUDE_DIRS}) -endif(${WIN32}) - -set(NOOTINI_SRC - main.cpp - nootiniwindow.cpp - nchart.cpp - naudioloader.cpp - nootinisettings.cpp - - ../../src/plugins/charts/tchart.cpp - ../../src/plugins/charts/tabstractaxis.cpp - ../../src/plugins/charts/txaxis.cpp - ../../src/plugins/charts/tyaxis.cpp - ../../src/plugins/charts/ttiphandler.cpp - ../../src/plugins/charts/tgroupedqaunit.cpp - ../../src/plugins/settings/tvolumeslider.cpp - -) - -add_executable(nootini WIN32 ${NOOTINI_SRC}) -target_link_libraries(nootini NootkaScore NootkaSound Qt5::Widgets Qt5::Svg) - diff --git a/tests/nootini/TODO b/tests/nootini/TODO deleted file mode 100644 index 440cb6587c4c34ea8042cc6259f13b7a7f65973f..0000000000000000000000000000000000000000 --- a/tests/nootini/TODO +++ /dev/null @@ -1,7 +0,0 @@ -Nootini TODO list - -- WAV headers are implemented in simple way only -- add 'stop' button to terminate processing -- some operation are allowed during processing but they should not (opening new file, starting new pass) -- x axis scaling (xSc) may depend on pitch range (frames per chunk) to make x axis the same -- there are many code from analyzer - make library of it diff --git a/tests/nootini/main.cpp b/tests/nootini/main.cpp deleted file mode 100644 index 107ab5bc8c5eae14aa7031620d02708343067648..0000000000000000000000000000000000000000 --- a/tests/nootini/main.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - - -#include <QtCore/QTranslator> -#include <QtCore/QDir> -#include <QtCore/QPluginLoader> -#include <QtCore/QDebug> -#include <QtWidgets/QApplication> -#include <tinitcorelib.h> -#include "nootiniwindow.h" - - -Tglobals *gl; - -int main(int argc, char *argv[]) -{ - QTranslator qtTranslator; - QTranslator nooTranslator; - QApplication a(argc, argv); - a.setApplicationName("Nootini"); - gl = new Tglobals(); // load configuration from temp file - gl->path = Tglobals::getInstPath(qApp->applicationDirPath()); - if (!initCoreLibrary()) - return 110; - prepareTranslations(&a, qtTranslator, nooTranslator); - if (!loadNootkaFont(&a)) - return 111; - - QString fName = ""; - if (a.arguments().size() > 1) - fName = a.arguments()[1]; - NootiniWindow nw(fName); - nw.show(); - - int exitCode = a.exec(); - - delete gl; - return exitCode; -} diff --git a/tests/nootini/naudioloader-libsndfile.cpp b/tests/nootini/naudioloader-libsndfile.cpp deleted file mode 100644 index 2aa997635eb04001f72c56398c33269013159158..0000000000000000000000000000000000000000 --- a/tests/nootini/naudioloader-libsndfile.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015-2016 by Tomasz Bojczuk * - * tomaszbojczuk@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#include "naudioloader.h" -#include <tpitchfinder.h> -#include <tinitcorelib.h> -#include <taudioparams.h> -#include <QtCore/qendian.h> -#include <QtCore/qdebug.h> -#include <QtWidgets/qmessagebox.h> - - -/*static*/ -int NaudioLoader::m_range = 1; - -NaudioLoader::NaudioLoader(QObject* parent) : - QObject(parent), - m_pf(0), - m_sndFile(0) -{ -} - - -NaudioLoader::~NaudioLoader() { - delete m_pf; -} - - -bool NaudioLoader::setAudioFile(const QString& fileName) { - if (m_pf) { - delete m_pf; - m_pf = 0; - } - m_pf = new TpitchFinder; - m_pf->setOffLine(true); - bool ok = true; - if (!fileName.isEmpty()) { - m_fileName = fileName; - SF_INFO sndInfo; - m_sndFile = sf_open(fileName.toStdString().data(), SFM_READ, &sndInfo); - if (sndInfo.format & SF_FORMAT_WAV && sndInfo.format & SF_FORMAT_PCM_16) { - qDebug() << "supported WAV format detected" << "frames" << sndInfo.frames << "channels" << sndInfo.channels - << "sample rate" << sndInfo.samplerate << "sections" << sndInfo.sections << "seekable" << sndInfo.seekable; - ok = true; - m_channelsNr = sndInfo.channels; - m_samplesCount = sndInfo.frames; - m_pf->setSampleRate(sndInfo.samplerate, m_range); - m_totalChunks = m_samplesCount / m_pf->aGl()->framesPerChunk + 1; - qDebug() << "chunks to go:" << m_totalChunks; - } else - QMessageBox::warning(0, QLatin1String("Nootini"), tr("Only WAV with 16 bit per sample are supported.")); - } - return ok; -} - - -void NaudioLoader::startLoading() { - connect(m_pf, SIGNAL(noteFinished(TnoteStruct*)), this, SLOT(forwardNoteFinished(TnoteStruct*)), Qt::UniqueConnection); - connect(m_pf, SIGNAL(volume(float)), this, SLOT(chunkProcessed()), Qt::UniqueConnection); - sf_seek(m_sndFile, 0, SEEK_SET); - performThread(); -} - - -void NaudioLoader::fillTartiniParams(TartiniParams* tp) { - if (m_pf) { - m_pf->aGl()->threshold = tp->threshold; - m_pf->aGl()->doingHarmonicAnalysis = tp->doingHarmonicAnalysis; - m_pf->aGl()->equalLoudness = Tcore::gl()->A->equalLoudness; - m_pf->aGl()->dBFloor = tp->dBFloor; - m_pf->aGl()->doingAutoNoiseFloor = tp->doingAutoNoiseFloor; - m_pf->setSkipStillerVal(Tcore::gl()->A->skipStillerVal / 100.0); - m_pf->setMinimalDuration(Tcore::gl()->A->minDuration); - m_pf->setSplitByVolChange(Tcore::gl()->A->minSplitVol > 0.0); - m_pf->setSplitVolume(Tcore::gl()->A->minSplitVol / 100.0); - m_pf->stop(true); - m_totalChunks = m_samplesCount / m_pf->aGl()->framesPerChunk + 1; - } -} - -//################################################################################################# -//################### PROTECTED ############################################ -//################################################################################################# - -void NaudioLoader::chunkProcessed() { - if (m_pf->currentChunk() > m_totalChunks - 1) { - emit processingFinished(); - sf_close(m_sndFile); - } else { - emit chunkReady(); - performThread(); - } -} - - -void NaudioLoader::threadFinished() { - -} - - -void NaudioLoader::performThread() { - qint16 chL; - qint16 frame[2]; - qint16* outBuffer = new qint16[m_pf->aGl()->framesPerChunk]; - for (int i = 0; i < m_pf->aGl()->framesPerChunk; ++i) { - if (m_samplesCount > m_pf->currentChunk() * m_pf->aGl()->framesPerChunk + i) { - if (m_channelsNr == 2) { - sf_readf_short(m_sndFile, frame, 1); - chL = frame[1]; -// chR = frame[0]; -// chL = ((qint32)chL + (qint32)chR) / 2; // mix channels to mono, FIXME: but it doesn't work always - } else { - sf_read_short(m_sndFile, &chL, 1); - } - outBuffer[i] = chL; - } else - outBuffer[i] = 0; - } - m_pf->copyToBufferOffline(outBuffer); - delete[] outBuffer; -} - - -void NaudioLoader::forwardNoteFinished(TnoteStruct* note) { - emit noteFinished(note); -} - - - - - - diff --git a/tests/nootini/naudioloader-libsndfile.h b/tests/nootini/naudioloader-libsndfile.h deleted file mode 100644 index 2e8b69a40edf01c0d826ca255f44cdf80f6c2ac8..0000000000000000000000000000000000000000 --- a/tests/nootini/naudioloader-libsndfile.h +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015-2016 by Tomasz Bojczuk * - * tomaszbojczuk@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifndef NAUDIOLOADER_H -#define NAUDIOLOADER_H - -#include <QtCore/qobject.h> -#include <sndfile.h> - - -class TnoteStruct; -class TartiniParams; -class TpitchFinder; - - -/** - * Manages loading audio data from file in separate thread. - * Grabbed data are push to @class TpitchFinder (in offline mode) - * After all, @p processingFinished() signal is emitted. - */ -class NaudioLoader : public QObject -{ - Q_OBJECT -public: - explicit NaudioLoader(QObject* parent = 0); - virtual ~NaudioLoader(); - - /** Sets audio file to be loaded with @p startLoading(). - * Only when file is set a valid @p TpitchFinder is returned by @p finder() */ - bool setAudioFile(const QString& fileName); - void startLoading(); /** Starts loading audio data and push it into TpitchFinder. */ - - TpitchFinder* finder() { return m_pf; } /** Pointer to @class TpitchFinder processing data of current file or 0 if no file. */ - - int totalChunks() { return m_totalChunks; } - - void fillTartiniParams(TartiniParams* tp); /** Applies Tartini parameters to existing @class TpitchFinder instance */ - - float volume() { return m_volume; } /** The strength value of amplitude in current chunk. */ - quint32 sampleRate() { return m_sampleRate; } - - static int pitchRange() {return m_range;} - static void setPitchRange(int range) { m_range = qBound<int>(0, range, 2); } - - QString fileName() { return m_fileName; } - -signals: - void processingFinished(); /** Emitted when all data were processed */ - void noteFinished(TnoteStruct*); /** Forwarded from @class TpitchFinder */ - void chunkReady(); - -protected: - void performThread(); - -protected slots: - void forwardNoteFinished(TnoteStruct *note); - void chunkProcessed(); - void threadFinished(); - - -private: - TpitchFinder *m_pf; - int m_totalChunks, m_samplesCount; - quint16 m_channelsNr; - quint32 m_sampleRate; - SNDFILE *m_sndFile; - float m_volume; - static int m_range; - QString m_fileName; -}; - -#endif // NAUDIOLOADER_H diff --git a/tests/nootini/naudioloader.cpp b/tests/nootini/naudioloader.cpp deleted file mode 100644 index c65999a003591850e5932533a83ac870a44e5a85..0000000000000000000000000000000000000000 --- a/tests/nootini/naudioloader.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015-2016 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#include "naudioloader.h" -#include <tpitchfinder.h> -#include <tinitcorelib.h> -#include <taudioparams.h> -#include <QtCore/qendian.h> -#include <QtWidgets/QtWidgets> - - -/*static*/ -int NaudioLoader::m_range = 1; - -NaudioLoader::NaudioLoader(QObject* parent) : - QObject(parent), - m_pf(0) -{ -} - - -NaudioLoader::~NaudioLoader() { - delete m_pf; -} - - -bool NaudioLoader::setAudioFile(const QString& fileName) { - if (m_pf) { - delete m_pf; - m_pf = 0; - } - m_pf = new TpitchFinder; - m_pf->setOffLine(true); - bool ok = true; - m_audioFile.setFileName(fileName); - if (m_audioFile.open(QIODevice::ReadOnly)) { - m_in.setDevice(&m_audioFile); - QString audioExt = fileName.right(3); - if (audioExt == QLatin1String("pcm") || audioExt == QLatin1String("raw")) { - quint64 headInfo; - m_in >> headInfo; - if (headInfo & 0x97042300) { - m_channelsNr = 1; - int sr = headInfo % 0x97042300; - if (sr == 44) - m_sampleRate = 44100; - else if (sr == 88) - m_sampleRate = 88200; - else - m_sampleRate = sr * 1000; - m_samplesCount = (m_audioFile.size() - 8) / 2; - } else { - QMessageBox::warning(nullptr, QLatin1String("Nootini"), tr("Raw file created out of Nootka are not supported yet")); - m_channelsNr = 1; - m_sampleRate = 48000; - ok = false; - } - } else { // WAV file - qint32 headChunk; - m_in >> headChunk; - headChunk = qFromBigEndian<qint32>(headChunk); - QString headStr((char*)&headChunk); - - quint32 chunkSize; - m_in >> chunkSize; - chunkSize = qFromBigEndian<quint32>(chunkSize); - m_in >> headChunk; - headChunk = qFromBigEndian<qint32>(headChunk); - headStr = QString((char*)&headChunk); - - if (headChunk == 1163280727) { // 1163280727 is 'value' of 'WAVE' text in valid WAV file - m_in >> headChunk; - headChunk = qFromBigEndian<qint32>(headChunk); - - m_in >> chunkSize; - quint16 audioFormat; - m_in >> audioFormat; - audioFormat = qFromBigEndian<quint16>(audioFormat); - if (headChunk == 544501094 && audioFormat == 1) { // 544501094 is 'value' of 'fmt ' text in valid WAV file - m_in >> m_channelsNr; - m_channelsNr = qFromBigEndian<quint16>(m_channelsNr); - m_in >> m_sampleRate; - m_sampleRate = qFromBigEndian<quint32>(m_sampleRate); - quint32 byteRate; - m_in >> byteRate; - byteRate = qFromBigEndian<quint32>(byteRate); - quint16 blockAlign; - m_in >> blockAlign; - blockAlign = qFromBigEndian<quint16>(blockAlign); - quint16 bitsPerSample; - m_in >> bitsPerSample; - bitsPerSample = qFromBigEndian<quint16>(bitsPerSample); - if (bitsPerSample != 16) { - QMessageBox::warning(nullptr, QLatin1String("Nootini"), tr("Only WAV with 16 bit per sample are supported.")); - ok = false; - } - m_in >> headChunk; - headChunk = qFromBigEndian<qint32>(headChunk); - headStr = QString((char*)&headChunk); - - quint32 audioDataSize; - m_in >> audioDataSize; - audioDataSize = qFromBigEndian<quint32>(audioDataSize); - - m_samplesCount = (audioDataSize / (m_channelsNr * 2)); - } else { - QMessageBox::warning(nullptr, QLatin1String("Nootini"), tr("Unsupported audio format in file:") + "<br>" + fileName); - ok = false; - } - } else { - QMessageBox::warning(nullptr, QLatin1String("Nootini"), fileName + "<br>" + tr("is not valid WAV file")); - ok = false; - } - } - } else { - QMessageBox::warning(nullptr, QLatin1String("Nootini"), tr("Cannot open file:") + "<br>" + fileName); - } - - if (ok) { - m_totalChunks = m_samplesCount / m_pf->aGl()->framesPerChunk + 1; - m_pf->setSampleRate(m_sampleRate, m_range); - qDebug() << fileName; - qDebug() << "channels:" << m_channelsNr << "sample rate:" << m_sampleRate << "chunks to go:" << m_totalChunks; - } - - if (!ok && m_audioFile.isOpen()) - m_audioFile.close(); - return ok; -} - - -void NaudioLoader::startLoading() { - if (m_audioFile.isOpen()) { - connect(m_pf, SIGNAL(noteFinished(TnoteStruct*)), this, SLOT(forwardNoteFinished(TnoteStruct*)), Qt::UniqueConnection); - connect(m_pf, SIGNAL(volume(float)), this, SLOT(chunkProcessed()), Qt::UniqueConnection); - performThread(); - } else - qDebug() << "Wrong file" << m_audioFile.fileName(); -} - - -void NaudioLoader::fillTartiniParams(TartiniParams* tp) { - if (m_pf) { - m_pf->aGl()->threshold = tp->threshold; - m_pf->aGl()->doingHarmonicAnalysis = tp->doingHarmonicAnalysis; - m_pf->aGl()->equalLoudness = Tcore::gl()->A->equalLoudness; - m_pf->aGl()->dBFloor = tp->dBFloor; - m_pf->aGl()->doingAutoNoiseFloor = tp->doingAutoNoiseFloor; - m_pf->setSkipStillerVal(Tcore::gl()->A->skipStillerVal / 100.0); - m_pf->setMinimalDuration(Tcore::gl()->A->minDuration); - m_pf->setSplitByVolChange(Tcore::gl()->A->minSplitVol > 0.0); - m_pf->setSplitVolume(Tcore::gl()->A->minSplitVol / 100.0); - m_pf->stop(true); - m_totalChunks = m_samplesCount / m_pf->aGl()->framesPerChunk + 1; - } -} - -//################################################################################################# -//################### PROTECTED ############################################ -//################################################################################################# - -void NaudioLoader::chunkProcessed() { - if (m_pf->currentChunk() > m_totalChunks - 1) { - emit processingFinished(); - m_audioFile.close(); - } else { - emit chunkReady(); - performThread(); - } -} - - -void NaudioLoader::threadFinished() { - -} - - -void NaudioLoader::performThread() { - qint16 chL, chR; - qint16* buffer = new qint16[m_pf->aGl()->framesPerChunk]; - for (int i = 0; i < m_pf->aGl()->framesPerChunk; ++i) { - if (m_samplesCount > m_pf->currentChunk() * m_pf->aGl()->framesPerChunk + i) { - m_in >> chL; - chL = qFromBigEndian<qint16>(chL); - if (m_channelsNr == 2) { - m_in >> chR; -// chR = qFromBigEndian<qint16>(chR); -// chL = ((qint32)chL + (qint32)chR) / 2; // mix channels to mono FIXME: mixing doesn't work in all cases - } - buffer[i] = chL; - } else - buffer[i] = 0; - } - m_pf->copyToBufferOffline(buffer); - delete[] buffer; -} - - -void NaudioLoader::forwardNoteFinished(TnoteStruct* note) { - emit noteFinished(note); -} - - - - - - diff --git a/tests/nootini/naudioloader.h b/tests/nootini/naudioloader.h deleted file mode 100644 index 72ae817955428ff54933bcd435a67175997d9885..0000000000000000000000000000000000000000 --- a/tests/nootini/naudioloader.h +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifndef NAUDIOLOADER_H -#define NAUDIOLOADER_H - -#include <QtCore/QObject> -#include <QtCore/QThread> -#include <QtCore/QFile> -#include <QtCore/QDataStream> - -class TnoteStruct; -class TartiniParams; -class TpitchFinder; - -/** - * Manages loading audio data from file in separate thread. - * Grabbed data are push to @class TpitchFinder (in offline mode) - * After all, @p processingFinished() signal is emitted. - */ -class NaudioLoader : public QObject -{ - Q_OBJECT -public: - explicit NaudioLoader(QObject* parent = 0); - virtual ~NaudioLoader(); - - /** Sets audio file to be loaded with @p startLoading(). - * Only when file is set a valid @p TpitchFinder is returned by @p finder() */ - bool setAudioFile(const QString& fileName); - void startLoading(); /** Starts loading audio data and push it into TpitchFinder. */ - - TpitchFinder* finder() { return m_pf; } /** Pointer to @class TpitchFinder processing data of current file or 0 if no file. */ - - int totalChunks() { return m_totalChunks; } - - void fillTartiniParams(TartiniParams* tp); /** Applies Tartini parameters to existing @class TpitchFinder instance */ - - float volume() { return m_volume; } /** The strength value of amplitude in current chunk. */ - quint32 sampleRate() { return m_sampleRate; } - - static int pitchRange() {return m_range;} - static void setPitchRange(int range) { m_range = qBound<int>(0, range, 2); } - - QString fileName() { return m_audioFile.fileName(); } - -signals: - void processingFinished(); /** Emitted when all data were processed */ - void noteFinished(TnoteStruct*); /** Forwarded from @class TpitchFinder */ - void chunkReady(); - -protected: - void performThread(); - -protected slots: - void forwardNoteFinished(TnoteStruct *note); - void chunkProcessed(); - void threadFinished(); - - -private: - QThread m_thread; - TpitchFinder *m_pf; - int m_totalChunks, m_samplesCount; - quint16 m_channelsNr; - quint32 m_sampleRate; - QDataStream m_in; - QFile m_audioFile; - float m_volume; - static int m_range; -}; - -#endif // NAUDIOLOADER_H diff --git a/tests/nootini/nchart.cpp b/tests/nootini/nchart.cpp deleted file mode 100644 index 1c5661cf00b04ab1d7a61a75afadff1eea73fc95..0000000000000000000000000000000000000000 --- a/tests/nootini/nchart.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015-2016 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#include "nchart.h" -#include "naudioloader.h" -#include <txaxis.h> -#include <tartini/notedata.h> -#include <tartini/channel.h> -#include <tpitchfinder.h> -#include <music/tnote.h> -#include <music/tnotestruct.h> -#include <tinitcorelib.h> -#include <taudioparams.h> -#include <tscorescene.h> -#include <tscorestaff.h> -#include <tscoreclef.h> -#include <graphics/tgraphicstexttip.h> -#include <tscoreparams.h> -#include <tcolor.h> -#include <QtWidgets/QApplication> -#include <QtWidgets/QScrollBar> -#include <QtCore/QDebug> -#include <QTimer> - - -#if defined(Q_OS_WIN32) - #include <windows.h> - #define SLEEP(msecs) Sleep(msecs) -#else - #include <unistd.h> - #define SLEEP(msecs) usleep(msecs * 1000) -#endif - -QColor minVolumeColor = QColor(0, 0, 255); -QColor noteVolumeColor = QColor(120, 255, 0); -QColor pcmVolumeColor = Qt::magenta; -QColor perfectPitchColor = Qt::darkGreen; -QColor averPitchColor = Qt::gray; -QColor bestPitchColor = QColor(103, 0, 103); -QColor chunkPitchColor = Qt::cyan; -QColor emptyColor = Qt::darkGray; -QColor minDurColor = Qt::blue; - - -QString yOrN(bool yn) { - return yn ? "<b>yes</b>" : "<b>no</b>"; -} - - -Nchart::Nchart(QWidget* parent) : - Tchart(parent), - m_pitchF(0), - m_totalXnr(0), - m_pitchGrad(0.5, 0, 0.5, 1), - xSc(4), hSc(2), - m_pass(-1), - m_currChunk(0), m_prevChunk(0), - m_drawnPrev(-1) -{ - yAxis->hide(); - xAxis->hide(); - yAxis->setLength(400); - yAxis->setMaxValue(140, false); - - m_progresItem = new TgraphicsTextTip("", palette().highlight().color()); - scene->addItem(m_progresItem); - m_progresItem->setZValue(250); - m_progresItem->setScale(2); - m_progresItem->hide(); - m_progresItem->setFlag(QGraphicsItem::ItemIgnoresTransformations); - - m_pitchGrad.setCoordinateMode(QGradient::ObjectBoundingMode); - const int al = 200; - m_pitchGrad.setColorAt(0, QColor(117, 21, 86, al)); - m_pitchGrad.setColorAt(0.1, QColor(255, 0, 0, al)); - m_pitchGrad.setColorAt(0.3, QColor(255, 255, 0, al)); - m_pitchGrad.setColorAt(0.5, QColor(0, 255, 0, al)); -// m_pitchGrad.setColorAt(0.55, QColor(0, 255, 0, al)); - m_pitchGrad.setColorAt(0.7, QColor(255, 255, 0, al)); - m_pitchGrad.setColorAt(0.9, QColor(255, 0, 0, al)); - m_pitchGrad.setColorAt(1.0, QColor(117, 21, 86, al)); - - m_staff = new TscoreStaff(scene, 0); - m_staff->setScale((yMap(0) - yMap(60)) / m_staff->height()); - m_staff->setViewWidth(400 / m_staff->scale()); - m_staff->setPos(22, yMap(50)); - m_staff->onClefChanged(Tcore::gl()->S->clef); - connect(m_staff, &TscoreStaff::clefChanged, this, &Nchart::clefChanged); - QTimer::singleShot(1, this, SLOT(adjustHeight())); -} - - -Nchart::~Nchart() -{ -} - - -void Nchart::setAudioLoader(NaudioLoader* loader) { - m_pass++; - m_loader = loader; - m_pitchF = loader->finder(); - m_chunkNr = -1; - connect(m_loader, &NaudioLoader::chunkReady, this, &Nchart::drawChunk, Qt::UniqueConnection); - connect(m_loader, &NaudioLoader::processingFinished, this, &Nchart::allDataLoaded, Qt::UniqueConnection); - connect(m_pitchF, &TpitchFinder::noteStarted, this, &Nchart::noteStartedSlot, Qt::UniqueConnection); - connect(m_loader, &NaudioLoader::noteFinished, this, &Nchart::copyChunk, Qt::UniqueConnection); - m_progresItem->show(); - m_prevNoteIndex = 0; - m_prevChunk = 0; - m_ad = 0; - m_pad = 0; - horizontalScrollBar()->setValue(0); - - if (m_pass) { // another processing on existing chart - TYaxis *oldYaxis = yAxis; - yAxis = new TYaxis; - scene->addItem(yAxis); - yAxis->setLength(400); - yAxis->setMaxValue(140, false); - yAxis->setZValue(55); - yAxis->setPos(45, oldYaxis->y() + oldYaxis->length() + 5 - (m_drawVolume ? 0 : 130)); - yAxis->hide(); - - TscoreStaff *oldStaff = m_staff; - m_staff = new TscoreStaff(scene, 0); - m_staff->setScale(oldStaff->scale()); - m_staff->setPos(oldStaff->x(), yMap(50)); - m_staff->onClefChanged(oldStaff->scoreClef()->clef()); - } - setXnumber(m_loader->totalChunks() + 1); - m_staff->setDisabled(true); - QTimer::singleShot(250, this, SLOT(progressSlot())); -} - - -void Nchart::setXnumber(int xN) { - m_xLine = new QGraphicsLineItem; - scene->addItem(m_xLine); - m_xLine->setPen(QPen(palette().text().color(), 2)); - m_xLine->setZValue(2); - m_xLine->setLine(52, yAxis->y() + yAxis->boundingRect().height(), (xN + 15) * xSc, yAxis->y() + yAxis->boundingRect().height()); - m_totalXnr = xN; - m_staff->setViewWidth(m_xLine->line().length() / m_staff->scale()); - qreal secondStep = xSc * (qreal)m_pitchF->aGl()->rate / (qreal)m_pitchF->aGl()->framesPerChunk; - for (int i = 0; i <= m_xLine->line().length() / secondStep; ++i) { - scene->addLine(QLineF(52 + i * secondStep, yMap(0), 52 + i * secondStep, yMap(0) + 3), m_xLine->pen()); - QGraphicsTextItem *ticText = scene->addText(QString("%1").arg(i)); - ticText->setPos(52 + i * secondStep - ticText->boundingRect().width() / 2, yMap(0) + 3); - QGraphicsLineItem *l = scene->addLine(52 + i * secondStep, yMap(1), 52 + i * secondStep, yMap(m_drawVolume ? 152 : 102), - QPen(Qt::lightGray, 1, Qt::DashLine)); - l->setZValue(1); - } - for (int i = 1; i <= m_xLine->line().length() / xSc; ++i) - scene->addLine(QLineF(52 + i * xSc, yMap(0), 52 + i * xSc, yMap(0) - 2), - QPen(palette().text().color(), 0.5)); - QGraphicsTextItem *timeText = scene->addText(tr("time [s]") + " "); - timeText->setPos(52 + m_xLine->line().length(), yMap(0) + 3); -// VOLUME - if (m_drawVolume) { - scene->addLine(xMap(1), yMap(101 + Tcore::gl()->A->minimalVol * 50.0), // minimum volume line - xMap(m_totalXnr), yMap(101 + Tcore::gl()->A->minimalVol * 50.0), QPen(minVolumeColor, 1)); - QGraphicsTextItem *minVolText = scene->addText(tr("min volume")); - minVolText->setDefaultTextColor(minVolumeColor); - minVolText->setPos(xMap(1) - minVolText->boundingRect().width(), - yMap(101 + Tcore::gl()->A->minimalVol * 50.0) - minVolText->boundingRect().height() / 2); - QGraphicsTextItem *noteVolText = scene->addText((tr("note volume"))); - noteVolText->setDefaultTextColor(noteVolumeColor); - noteVolText->setPos(xMap(1) - minVolText->boundingRect().width(), yMap(150)); - scene->addLine(xMap(1), yMap(101), xMap(m_totalXnr) , yMap(101), QPen(palette().text().color(), 1)); // X axis of volume chart - QGraphicsTextItem *pcmSigText = scene->addText(tr("PCM volume")); - pcmSigText->setDefaultTextColor(pcmVolumeColor); - pcmSigText->setPos(xMap(1) - pcmSigText->boundingRect().width(), yMap(100) - pcmSigText->boundingRect().height()); - } -// PITCH - QGraphicsRectItem *bgPitch = scene->addRect(xMap(1), yMap(100), (xN - 5) * xSc, yMap(50) - yMap(100), - Qt::NoPen, QBrush(m_pitchGrad)); - bgPitch->setZValue(5); -// perfect pitch line in the middle of a rectangle - QGraphicsLineItem *pitchLine = scene->addLine(xMap(1), yMap(75), xMap(xN - 4), yMap(75), QPen(perfectPitchColor, 1)); - pitchLine->setZValue(12); - - QGraphicsTextItem *pitchTexts = new QGraphicsTextItem(); - scene->addItem(pitchTexts); - pitchTexts->setHtml("<span style=\"color: " + chunkPitchColor.name() + "\";>" + tr("chunk pitch") + "</span><br>" + - "<span style=\"color: " + perfectPitchColor.name() + "\";>" + tr("perfect pitch") + "</span><br>" + - "<span style=\"color: " + bestPitchColor.name() + "\";>" + tr("closest pitch") + "</span><br>" + - "<span style=\"color: " + averPitchColor.name() + "\";>" + tr("average pitch") + "</span>"); - pitchTexts->setPos(xMap(0) - pitchTexts->boundingRect().width(), yMap(75) - pitchTexts->boundingRect().height() / 2); - QGraphicsTextItem *settingsTexts = new QGraphicsTextItem(); - scene->addItem(settingsTexts); - QString pdm = "MPM"; - if (Tcore::gl()->A->detectMethod == 1) - pdm = "autocorelation"; - else if (Tcore::gl()->A->detectMethod == 2) - pdm = "mod. cepstrum"; - QString rangeText = "middle (1024)"; - if (NaudioLoader::pitchRange() == TpitchFinder::e_high) - rangeText = "high (512)"; - else if (NaudioLoader::pitchRange() == TpitchFinder::e_low) - rangeText = "low (2048)"; - settingsTexts->setHtml(tr("method") + ": <b>" + pdm +"</b><br>" + - tr("filter") + " :" + yOrN(Tcore::gl()->A->equalLoudness) + "<br>" + - QString("noise-floor: <b>%1</b>").arg(yOrN(m_pitchF->aGl()->doingAutoNoiseFloor)) + "<br>" + - QString("pitch range: <b>%1</b>").arg(rangeText) + "<br>" + - tr("threshold") + QString(": <b>%1 %</b>").arg(m_pitchF->aGl()->threshold) + "<br>" + - "<span style=\"color: " + noteVolumeColor.name() + "\";>" + QString("split vol.: <b>%1</b>"). - arg((m_pitchF->isSplitByVolume() ? QString("%1%").arg(Tcore::gl()->A->minSplitVol) : "no")) + "</span><br>" + - "<span style=\"color: " + noteVolumeColor.name() + "\";>" + QString("skip stiller: <b>%1</b>"). - arg((m_pitchF->skipStillerValue() > 0.0 ? QString("%1%").arg(Tcore::gl()->A->skipStillerVal) : "no")) + "</span><br>" + - QString("dbFoor: <b>%1</b>").arg(m_pitchF->aGl()->dBFloor) + "<br>" + - QString("middle A: <b>%1 [Hz]</b>").arg(pitch2freq(freq2pitch(440) + Tcore::gl()->A->a440diff)) + "<br>" + - "<span style=\"color: " + minVolumeColor.name() + "\";>" + QString("min. volume: <b>%1</b>").arg(Tcore::gl()->A->minimalVol * 100) + "</span><br>" - "<span style=\"color: " + minDurColor.name() + "\";>" + QString("min. duration: <b>%1 [ms]</b>").arg(Tcore::gl()->A->minDuration * 1000) + "</span>" + - QString("<br>chunk time: <b>%1 [ms]</b>").arg(m_pitchF->chunkTime() * 1000)); - settingsTexts->setPos(xMap(xN - 2), yMap(110)); -} - - -void Nchart::allDataLoaded() { - m_progresItem->hide(); -} - - -//################################################################################################# -//################### PROTECTED ############################################ -//################################################################################################# - -void Nchart::copyChunk(TnoteStruct* ad) { - for (int i = m_prevChunk; i < ad->startChunk; ++i) - emptyRect(i, xSc); - drawNoteSegment(ad->startChunk, ad->endChunk, ad); - m_prevChunk = ad->endChunk + 1; -} - - -void Nchart::drawChunk() { - if (m_pitchF->currentChunk() < 1) - return; - - int c = m_pitchF->currentChunk() - 1; - m_pad = m_ad; - m_ad = m_pitchF->ch()->dataAtChunk(c); - -// qDebug() << m_ad->noteIndex << m_ad->pitch << "ncs:" << m_ad->noteChangeScore() << "done" << m_ad->done << "pl:" << m_ad->notePlaying << m_ad->period; - - if (m_drawVolume && m_ad && m_pad) - scene->addLine(xMap(c - 1) + hSc, yMap(101 + m_pad->pcmVolume * 50.0), // PCM signal volume line - xMap(c) + hSc, yMap(101 + m_ad->pcmVolume * 50.0), QPen(pcmVolumeColor, 1, Qt::SolidLine, Qt::RoundCap)); - - if (m_ad) { - if (m_drawVolume) { - if (m_ad->normalVolume() && m_pad && m_pad->normalVolume()) { - QGraphicsLineItem *volLine = new QGraphicsLineItem(); // line with volumes of every chunk - scene->addItem(volLine); - volLine->setPen(QPen(noteVolumeColor, 2)); - volLine->setLine(xMap(c - 1) + hSc, yMap(101 + m_pad->normalVolume() * 50.0), - xMap(c) + hSc, yMap(101 + m_ad->normalVolume() * 50.0)); - } - } - } - qApp->processEvents(); -} - - -void Nchart::drawNoteSegment(int firstNoteChunk, int lastNoteChunk, TnoteStruct* ns) { - int minDurChunk = 0; - qreal shortSum = 0, totalSum = 0; - int lessDiffChunk; - bool loudEnough = false; - for (int i = firstNoteChunk; i <= lastNoteChunk; i++) { - if (m_pitchF->ch()->dataAtChunk(i)->normalVolume() >= Tcore::gl()->A->minimalVol) - loudEnough = true; - if (!minDurChunk && i - firstNoteChunk >= m_pitchF->minChunksNumber()) - minDurChunk = i; - if (i > firstNoteChunk + 2 && i < lastNoteChunk - 1) // average pitch from 'inner' chunks - shortSum += m_pitchF->ch()->dataAtChunk(i)->pitch; - totalSum += m_pitchF->ch()->dataAtChunk(i)->pitch; - } - if (ns) - loudEnough = ns->maxVol >= Tcore::gl()->A->minimalVol; - qreal shortAverPitch = shortSum / (lastNoteChunk - firstNoteChunk - 4) - Tcore::gl()->A->a440diff; - qreal averPitch = totalSum / (lastNoteChunk - firstNoteChunk + 1) - Tcore::gl()->A->a440diff; - if (ns) { - shortAverPitch = ns->shortAverage() - Tcore::gl()->A->a440diff; - averPitch = ns->totalAverage() - Tcore::gl()->A->a440diff; - } - QPolygonF pitchGon; - qreal lessDiff = 1.0; - qreal y25 = yMap(50) - yMap(100); - for (int i = firstNoteChunk; i <= lastNoteChunk; i++){ - qreal pi = m_pitchF->ch()->dataAtChunk(i)->pitch - Tcore::gl()->A->a440diff; - pitchGon << QPointF(xMap(i) + hSc, yMap(75) - qBound<qreal>(-y25 / 2, (pi - (qreal)qRound(shortAverPitch)) * y25, y25 / 2)); - if (qAbs<qreal>(pi - (qreal)qRound(shortAverPitch)) < lessDiff) { - lessDiff = qAbs<qreal>(pi - (qreal)qRound(shortAverPitch)); - lessDiffChunk = i; - } - } - -// ACCURACY BACKGROUND - if (!minDurChunk || !loudEnough) { - QGraphicsRectItem *bgPitch = new QGraphicsRectItem; - scene->addItem(bgPitch); - bgPitch->setZValue(10); - bgPitch->setPen(Qt::NoPen); - bgPitch->setBrush(emptyColor); - bgPitch->setRect(xMap(firstNoteChunk), yMap(100), - (lastNoteChunk - firstNoteChunk + 1) * xSc, yMap(50) - yMap(100)); - } - if (minDurChunk) { - QGraphicsLineItem *minDurLine = new QGraphicsLineItem; - scene->addItem(minDurLine); - minDurLine->setZValue(11); - minDurLine->setPen(QPen(minDurColor, 1)); - minDurLine->setLine(xMap(minDurChunk) + hSc, yMap(99), xMap(minDurChunk) + hSc, yMap(51)); - QGraphicsTextItem *durText = scene->addText(tr("min\nduration")); - durText->setDefaultTextColor(minDurColor); - durText->setScale(0.5); - durText->setPos(xMap(minDurChunk) + hSc - durText->boundingRect().width() / 4, yMap(51)); - QGraphicsTextItem *sumText = scene->addText(""); - sumText->setHtml(QString("<p style=\"" + Tcolor::bgTag(QColor(255, 255, 255, 50)) + "\">a: %1<br>b: %2</p>"). - arg(averPitch).arg(ns->bestPitch - Tcore::gl()->A->a440diff)); - sumText->setDefaultTextColor(minDurColor); - sumText->setScale(0.55); - sumText->setPos(xMap(minDurChunk) + xSc, yMap(99)); - sumText->setZValue(100); - } - QGraphicsLineItem *bestPitchLine = new QGraphicsLineItem; - scene->addItem(bestPitchLine); - bestPitchLine->setZValue(16); - bestPitchLine->setPen(QPen(bestPitchColor, 1)); - qreal pi = (m_pitchF->ch()->dataAtChunk(lessDiffChunk)->pitch - Tcore::gl()->A->a440diff) - - (float)qRound(m_pitchF->ch()->dataAtChunk(lessDiffChunk)->pitch - Tcore::gl()->A->a440diff); - if (ns) - pi = (ns->bestPitch - Tcore::gl()->A->a440diff) - (float)ns->basePitch; - qreal avY = yMap(75) - pi * y25; - bestPitchLine->setLine(xMap(firstNoteChunk), avY, xMap(lastNoteChunk) + xSc, avY); - - QGraphicsLineItem *averPitchLine = new QGraphicsLineItem; - scene->addItem(averPitchLine); - averPitchLine->setZValue(15); - averPitchLine->setPen(QPen(averPitchColor, 1)); - pi = averPitch - (float)qRound(averPitch); - avY = yMap(75) - pi * y25; - averPitchLine->setLine(xMap(firstNoteChunk), avY, xMap(lastNoteChunk) + xSc, avY); - -// QGraphicsLineItem *shortAverLine = new QGraphicsLineItem; -// scene->addItem(shortAverLine); -// shortAverLine->setZValue(15); -// shortAverLine->setPen(QPen(Qt::darkYellow, 1)); -// pi = shortAverPitch - (float)qRound(shortAverPitch); -// avY = yMap(75) - pi * y25; -// shortAverLine->setLine(xMap(firstNoteChunk + 2), avY, xMap(lastNoteChunk - 2), avY); - - QPainterPath pp; - pp.addPolygon(pitchGon); - QGraphicsPathItem *pitchDiffLine = new QGraphicsPathItem(pp); - scene->addItem(pitchDiffLine); - pitchDiffLine->setZValue(15); - pitchDiffLine->setPen(QPen(chunkPitchColor, 2, Qt::SolidLine, Qt::RoundCap)); -// Tnote n(qRound((ns ? ns->bestPitch : m_pitchF->ch()->dataAtChunk(lessDiffChunk)->pitch) - Tcore::gl()->A->a440diff) - 47); - Tnote shortNote(qRound(shortAverPitch) - 47); - m_staff->addNote(shortNote, true); - m_staff->noteSegment(m_staff->count() - 1)->setPos(m_staff->mapFromScene(xMap(firstNoteChunk), 0).x(), 0); - m_staff->noteSegment(m_staff->count() - 1)->showNoteName(); - if (!minDurChunk || !loudEnough) - m_staff->noteSegment(m_staff->count() - 1)->setColor(Qt::gray); - if (ns && loudEnough && minDurChunk) { - Tnote totalNote(qRound(ns->totalAverage() - Tcore::gl()->A->a440diff) - 47); - Tnote quickNote(qRound(ns->getAverage(3, m_pitchF->minChunksNumber()) - Tcore::gl()->A->a440diff) - 47); - if (totalNote != shortNote) { - m_staff->addNote(totalNote, true); - m_staff->noteSegment(m_staff->count() - 1)->setPos(m_staff->mapFromScene(xMap(lastNoteChunk), 0).x() - 2 * m_staff->scale(), 0); - m_staff->noteSegment(m_staff->count() - 1)->setColor(noteVolumeColor); - } - if (quickNote != shortNote) { - m_staff->addNote(quickNote, true); - m_staff->noteSegment(m_staff->count() - 1)->setPos(m_staff->mapFromScene(xMap(firstNoteChunk), 0).x() + 2 * m_staff->scale(), 0); - m_staff->noteSegment(m_staff->count() - 1)->setColor(minDurColor); - } - } -} - - -void Nchart::emptyRect(int firstChunk, qreal width) { - QGraphicsRectItem *emptyBg = new QGraphicsRectItem; - scene->addItem(emptyBg); - emptyBg->setZValue(10); - emptyBg->setPen(Qt::NoPen); - emptyBg->setBrush(emptyColor.lighter(160 + (10 * (firstChunk % 2)))); - emptyBg->setRect(xMap(firstChunk), yMap(100), width, yMap(50) - yMap(100)); -} - - -void Nchart::noteStartedSlot(qreal pitch, qreal freq, qreal duration) { -// Tnote n; -// n.fromMidi(qRound(pitch)); -// qDebug() << "started" << n.toText(); -} - - -void Nchart::progressSlot() { - if (m_pitchF->currentChunk() < m_totalXnr) { - m_progresItem->setHtml(tr("Detecting...") + QString("<big><b> %1%</b></big>"). - arg(int(((qreal)m_pitchF->currentChunk() / (qreal)(m_totalXnr)) * 100))); - QTimer::singleShot(250, this, SLOT(progressSlot())); - } -} - - -void Nchart::clefChanged(Tclef clef) { - Tcore::gl()->S->clef = clef.type(); -} - - -void Nchart::adjustHeight() { - qreal factor = (viewport()->rect().height() / scene->sceneRect().height()) * 0.95; - scale(factor, factor); -} - - -void Nchart::scrollContentsBy(int dx, int dy) { - QGraphicsView::scrollContentsBy(dx, dy); - if (m_progresItem->isVisible()) { - m_progresItem->setPos(mapToScene(0, 0)); - } -} - - - diff --git a/tests/nootini/nchart.h b/tests/nootini/nchart.h deleted file mode 100644 index b2082ba0a7821eb9249279ab074f9c15fb29587f..0000000000000000000000000000000000000000 --- a/tests/nootini/nchart.h +++ /dev/null @@ -1,101 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifndef NCHART_H -#define NCHART_H - -#include <tchart.h> -#include <tyaxis.h> -#include <music/tclef.h> -#include <QThread> -#include <QMutex> - -class TnoteStruct; -class TgraphicsTextTip; -class NaudioLoader; -class TscoreStaff; -class NoteData; -class AnalysisData; -class TpitchFinder; - -/** - * Nootini chart - */ -class Nchart : public Tchart -{ - - Q_OBJECT -public: - Nchart(QWidget* parent = 0); - virtual ~Nchart(); - - struct SnoteStruct { - int index; - qreal realPitch; - int basePitch; /** Rounded pitch value */ - qreal duration; - int chunkDur; /** How many chunks note takes */ - }; /** Values describing detected note after Nootka processing */ - - void setAudioLoader(NaudioLoader* loader); /** Pitch finder processing audio data */ - void setXnumber(int xN); /** Number of X values on the chart */ - - void allDataLoaded(); /** May be called when all data was sent to the chart to adjust its size */ - - void drawChunk(); - - bool drawVolume() { return m_drawVolume; } - void setDrawVolume(bool drawVol) { m_drawVolume = drawVol; } - -signals: - void chunkDone(); /** Emitted when @p chunkSlot() finished. */ - -protected: - void copyChunk(TnoteStruct* ad); - void clefChanged(Tclef clef); - void drawNoteSegment(int firstNoteChunk, int lastNoteChunk, TnoteStruct* ns = 0); - void emptyRect(int firstChunk, qreal width); - void noteStartedSlot(qreal pitch, qreal freq, qreal duration); - - int xMap(int xx) { return m_xLine->line().x1() + (xx + 1) * xSc; } - qreal yMap(qreal yy) { return yAxis->y() + yAxis->mapValue(yy); } - - virtual void scrollContentsBy(int dx, int dy) override; - -protected slots: - void adjustHeight(); - void progressSlot(); - -private: - TpitchFinder *m_pitchF; - TscoreStaff *m_staff; - TgraphicsTextTip *m_progresItem; - int m_chunkNr, m_prevNoteIndex; - int m_totalXnr; - QLinearGradient m_pitchGrad; - QGraphicsLineItem *m_xLine; - const int xSc, hSc; /** @p xSc is scale of x axis ans @p hSc is half of it */ - int m_pass; - bool m_drawVolume; - NaudioLoader *m_loader; - AnalysisData *m_ad, *m_pad; // current data and previous data - int m_currChunk, m_prevChunk; - int m_drawnPrev; -}; - -#endif // NCHART_H diff --git a/tests/nootini/nootinisettings.cpp b/tests/nootini/nootinisettings.cpp deleted file mode 100644 index 834a4bb073e752fd0c7a2dbc3bbd189ef623609b..0000000000000000000000000000000000000000 --- a/tests/nootini/nootinisettings.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#include "nootinisettings.h" -#include <tinitcorelib.h> -#include <taudioparams.h> -#include <tartiniparams.h> -#include <tpitchfinder.h> -#include <widgets/tintonationview.h> -#include <../settings/tvolumeslider.h> -#include <QtWidgets/QtWidgets> - - -NootiniSettings::NootiniSettings(TartiniParams* tp, QWidget* parent) : - QDialog(parent), - m_tartiniParams(tp) -{ - setWindowTitle(tr("Parameters of processing")); - setWindowIcon(parent->windowIcon()); - - QLabel *methodLab = new QLabel(tr("pitch detection mode"), this); - m_methodCombo = new QComboBox(this); - m_methodCombo->addItem("MPM"); - m_methodCombo->addItem("autocorrelation"); - m_methodCombo->addItem("MPM + modified cepstrum"); - if (Tcore::gl()->A->detectMethod == e_MPM) - m_methodCombo->setCurrentIndex(0); - else if (Tcore::gl()->A->detectMethod == e_AUTOCORRELATION) - m_methodCombo->setCurrentIndex(1); - else - m_methodCombo->setCurrentIndex(2); - - QLabel *durHeadLab = new QLabel(tr("minimum note duration"), this); - m_durationSpin = new QSpinBox(this); - m_durationSpin->setMinimum(10); - m_durationSpin->setMaximum(1000); - m_durationSpin->setSuffix(" " + tr("[milliseconds]")); - m_durationSpin->setSingleStep(50); - m_durationSpin->setValue(qRound(Tcore::gl()->A->minDuration * 1000)); // minimum duration is stored in seconds but displayed in milliseconds - - QLabel *volLabel = new QLabel(tr("minimum volume"), this); - m_volumeSlider = new TvolumeSlider(this); - m_volumeSlider->setValue(Tcore::gl()->A->minimalVol); - - m_lowRadio = new QRadioButton(tr("low") + " (2048)", this); - m_middleRadio = new QRadioButton(tr("middle") + " (1024)", this); - m_highRadio = new QRadioButton(tr("high") + " (512)", this); - QButtonGroup *rangeGr = new QButtonGroup(this); - rangeGr->addButton(m_lowRadio); - rangeGr->addButton(m_middleRadio); - rangeGr->addButton(m_highRadio); - - QLabel *frLab = new QLabel(tr("frequency:"), this); - m_freqSpin = new QSpinBox(this); - m_freqSpin->setMinimum(200); - m_freqSpin->setMaximum(900); - m_freqSpin->setSuffix(" Hz"); - m_freqSpin->setValue(qRound((pitch2freq(freq2pitch(440) + Tcore::gl()->A->a440diff)))); - - QLabel *threshLab = new QLabel(tr("threshold of lowest loudness (MPM methods)"), this); - m_thresholdSpin = new QSpinBox(this); - m_thresholdSpin->setRange(80, 100); - m_thresholdSpin->setSuffix(" %"); - m_thresholdSpin->setValue(m_tartiniParams->threshold); - - m_noiseFilterChB = new QCheckBox(tr("noise filter"), this); - m_noiseFilterChB->setChecked(Tcore::gl()->A->equalLoudness); - - m_calcNoiseChB = new QCheckBox(tr("Automatically calculate noise-floor"), this); - m_calcNoiseChB->setChecked(m_tartiniParams->doingAutoNoiseFloor); - - m_splitVolChB = new QCheckBox(tr("split when volume rise"), this); - - m_splitVolSpin = new QSpinBox(this); - m_splitVolChB->setChecked(Tcore::gl()->A->minSplitVol > 0.0); - m_splitVolSpin->setRange(5, 50); - m_splitVolSpin->setSingleStep(5); - m_splitVolSpin->setSuffix(" %"); - m_splitVolSpin->setValue(Tcore::gl()->A->minSplitVol); - - m_skipStillerChB = new QCheckBox(tr("skip stiller than"), this); - m_skipStillerSpin = new QSpinBox(this); - m_skipStillerSpin->setRange(10, 95); - m_skipStillerSpin->setSingleStep(5); - m_skipStillerSpin->setSuffix(" %"); - m_skipStillerSpin->setStatusTip(m_skipStillerChB->statusTip()); - m_skipStillerSpin->setValue(Tcore::gl()->A->skipStillerVal); - m_skipStillerChB->setChecked(Tcore::gl()->A->skipStillerVal > 0.0); - - QLabel *dbLab = new QLabel(tr("dbFloor"), this); - m_dbFlorSpin = new QDoubleSpinBox(this); - m_dbFlorSpin->setRange(-300, 0); - m_dbFlorSpin->setValue(m_tartiniParams->dBFloor); - - m_drawVolChB = new QCheckBox(tr("draw volume chart"), this); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); - - QVBoxLayout *lay = new QVBoxLayout; - QHBoxLayout *methodLay = new QHBoxLayout; - methodLay->addStretch(); - methodLay->addWidget(methodLab); - methodLay->addWidget(m_methodCombo); - methodLay->addStretch(); - lay->addLayout(methodLay); - QHBoxLayout *durLay = new QHBoxLayout; - durLay->addStretch(); - durLay->addWidget(durHeadLab); - durLay->addWidget(m_durationSpin, 0, Qt::AlignLeft); - durLay->addStretch(); - lay->addLayout(durLay); - QHBoxLayout *volLay = new QHBoxLayout; - volLay->addWidget(volLabel); - volLay->addWidget(m_volumeSlider); - lay->addLayout(volLay); - QHBoxLayout *rangeLay = new QHBoxLayout; - rangeLay->addWidget(m_lowRadio); - rangeLay->addWidget(m_middleRadio); - rangeLay->addWidget(m_highRadio); - QGroupBox *rangeBox = new QGroupBox(tr("Range of note pitches:"), this); - rangeBox->setLayout(rangeLay); - lay->addWidget(rangeBox); - QHBoxLayout *freqLay = new QHBoxLayout; - freqLay->addStretch(); - freqLay->addWidget(frLab); - freqLay->addWidget(m_freqSpin); - freqLay->addStretch(); - lay->addLayout(freqLay); - QHBoxLayout *threshLay = new QHBoxLayout; - threshLay->addStretch(); - threshLay->addWidget(threshLab); - threshLay->addWidget(m_thresholdSpin); - threshLay->addStretch(); - lay->addLayout(threshLay); - QHBoxLayout *noiseLay = new QHBoxLayout; - noiseLay->addStretch(); - noiseLay->addWidget(m_noiseFilterChB); - noiseLay->addStretch(); - noiseLay->addWidget(m_calcNoiseChB); - noiseLay->addStretch(); - lay->addLayout(noiseLay); - QHBoxLayout *splitLay = new QHBoxLayout; - splitLay->addStretch(); - splitLay->addWidget(m_splitVolChB); - splitLay->addWidget(m_splitVolSpin); - splitLay->addStretch(); - splitLay->addWidget(m_skipStillerChB); - splitLay->addWidget(m_skipStillerSpin); - splitLay->addStretch(); - lay->addLayout(splitLay); - QHBoxLayout *dbLay = new QHBoxLayout; - dbLay->addStretch(); - dbLay->addWidget(dbLab); - dbLay->addWidget(m_dbFlorSpin); - dbLay->addStretch(); - lay->addLayout(dbLay); - QHBoxLayout *nootLay = new QHBoxLayout; - nootLay->addStretch(); - nootLay->addWidget(m_drawVolChB); - nootLay->addStretch(); - lay->addLayout(nootLay); - lay->addWidget(buttonBox); - setLayout(lay); - - connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - connect(m_splitVolChB, &QCheckBox::toggled, this, &NootiniSettings::splitByVolChanged); - connect(m_skipStillerChB, &QCheckBox::toggled, this, &NootiniSettings::skipStillerChanged); - -} - - -bool NootiniSettings::drawVolumeChart() { - return m_drawVolChB->isChecked(); -} - - -void NootiniSettings::setDrawVolumeChart(bool draw) { - m_drawVolChB->setChecked(draw); -} - - -void NootiniSettings::setRange(int r) { - TpitchFinder::Erange rang = (TpitchFinder::Erange)r; - switch (rang) { - case TpitchFinder::e_high: - m_highRadio->setChecked(true); break; // e_high - lowest pitch is F small - case TpitchFinder::e_low: - m_lowRadio->setChecked(true); break; // e_low - lowest pitch is ... very low - default: - m_middleRadio->setChecked(true); break; // e_middle - lowest pitch is F contra - } -} - - -int NootiniSettings::range() { - if (m_highRadio->isChecked()) - return TpitchFinder::e_high; - else if (m_lowRadio->isChecked()) - return TpitchFinder::e_low; - else - return TpitchFinder::e_middle; -} - - - -//################################################################################################# -//################### PROTECTED ############################################ -//################################################################################################# -void NootiniSettings::accept() { - Tcore::gl()->A->detectMethod = m_methodCombo->currentIndex(); - Tcore::gl()->A->minDuration = (qreal)m_durationSpin->value() / 1000.0; - Tcore::gl()->A->minimalVol = m_volumeSlider->value(); - if (m_freqSpin->value() == 440 ) - Tcore::gl()->A->a440diff = 0.0; - else - Tcore::gl()->A->a440diff = float(freq2pitch((double)m_freqSpin->value()) - freq2pitch(440.0)); - - m_tartiniParams->threshold = m_thresholdSpin->value(); - Tcore::gl()->A->equalLoudness = m_noiseFilterChB->isChecked(); - Tcore::gl()->A->minSplitVol = m_splitVolChB->isChecked() ? (qreal)m_splitVolSpin->value() : 0.0; - Tcore::gl()->A->skipStillerVal = m_skipStillerChB->isChecked() ? (qreal)m_skipStillerSpin->value() : 0.0; - m_tartiniParams->dBFloor = m_dbFlorSpin->value(); - m_tartiniParams->doingAutoNoiseFloor = m_calcNoiseChB->isChecked(); - - QDialog::accept(); -} - - - - - - diff --git a/tests/nootini/nootinisettings.h b/tests/nootini/nootinisettings.h deleted file mode 100644 index a09f5cd6737573753e4d26081890119815724837..0000000000000000000000000000000000000000 --- a/tests/nootini/nootinisettings.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifndef NOOTINISETTINGS_H -#define NOOTINISETTINGS_H - - -#include <QtWidgets/QDialog> -#include <QSpinBox> - -class QDoubleSpinBox; -class QGroupBox; -class QCheckBox; -class TartiniParams; -class QComboBox; -class TvolumeSlider; -class QRadioButton; - - -/** - * Nootini tool settings dialog window - */ -class NootiniSettings : public QDialog -{ - -public: - explicit NootiniSettings(TartiniParams* tp, QWidget* parent = 0); - - bool drawVolumeChart(); - void setDrawVolumeChart(bool draw); - - void setRange(int r); - int range(); - -protected: - virtual void accept(); - void splitByVolChanged(bool enab) { m_splitVolSpin->setDisabled(!enab); } - void skipStillerChanged(bool enab) { m_skipStillerSpin->setDisabled(!enab); } - -private: - QRadioButton *m_highRadio, *m_middleRadio, *m_lowRadio; - QSpinBox *m_freqSpin, *m_durationSpin, *m_thresholdSpin, *m_splitVolSpin, *m_skipStillerSpin; - QComboBox *m_methodCombo; - QDoubleSpinBox *m_dbFlorSpin; - TvolumeSlider *m_volumeSlider; - QCheckBox *m_noiseFilterChB, *m_calcNoiseChB, *m_drawVolChB; - QCheckBox *m_splitVolChB, *m_skipStillerChB; - TartiniParams *m_tartiniParams; -}; - -#endif // NOOTINISETTINGS_H diff --git a/tests/nootini/nootiniwindow.cpp b/tests/nootini/nootiniwindow.cpp deleted file mode 100644 index 95c98c9a6bfe4bb58fcb83cca05411c7a2ccaad1..0000000000000000000000000000000000000000 --- a/tests/nootini/nootiniwindow.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015-2016 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#include "nootiniwindow.h" -#include "nchart.h" -#include "naudioloader.h" -#include "nootinisettings.h" -#include <graphics/tnotepixmap.h> -#include <tinitcorelib.h> -#include <tpath.h> -#include <tpitchfinder.h> -#include <QtWidgets/QtWidgets> -#include <QtSvg/qsvggenerator.h> - - -static bool m_drawVolume = true; -static QString m_lastAudioDir; - - -NootiniWindow::NootiniWindow(const QString& audioFile, QWidget* parent) : - QMainWindow(parent), - m_chart(0) -{ - readConfig(); - QFont nf("nootka", 256); - setWindowIcon(QIcon(pixFromString("m", nf, Qt::darkMagenta))); - resize(800, 600); - QWidget* innerWidget = new QWidget(this); - - QVBoxLayout* lay = new QVBoxLayout; - innerWidget->setLayout(lay); - setCentralWidget(innerWidget); - - QMenu *fileMenu = menuBar()->addMenu(tr("file")); - m_openAct = fileMenu->addAction(QIcon(style()->standardIcon(QStyle::SP_DirOpenIcon)), tr("open audio file"), - this, SLOT(openFileSlot()), QKeySequence::Open); - m_settAct = fileMenu->addAction(QIcon(style()->standardIcon(QStyle::QStyle::SP_DialogApplyButton)), tr("settings"), - this, SLOT(settingsSlot()), QKeySequence("Ctrl+E")); - m_againAct = fileMenu->addAction(QIcon(style()->standardIcon(QStyle::SP_MediaPlay)), tr("process again"), - this, SLOT(processAgain()), QKeySequence("Ctrl+space")); - m_againAct->setDisabled(true); - m_toSvgAct = fileMenu->addAction(QIcon(style()->standardIcon(QStyle::SP_DialogSaveButton)), tr("save to SVG"), - this, SLOT(saveAsSvg()), QKeySequence::Save); - m_toSvgAct->setDisabled(true); - - QMenu *chartMenu = menuBar()->addMenu(tr("chart")); - m_zoomInAct = chartMenu->addAction(QIcon(Tpath::img("zoom-in")), tr("zoom in"), - this, SLOT(zoom()), QKeySequence::ZoomIn); - m_zoomOutAct = chartMenu->addAction(QIcon(Tpath::img("zoom-out")), tr("zoom out"), - this, SLOT(zoom()), QKeySequence::ZoomOut); - m_zoomFitAct = chartMenu->addAction(QIcon(style()->standardIcon(QStyle::SP_ArrowUp)), tr("fit to height"), - this, SLOT(fitHeight()), QKeySequence("Ctrl+0")); - - m_loader = new NaudioLoader(); - - if (audioFile.isEmpty()) { - m_chart = new Nchart(); - lay->addWidget(m_chart); - } else - processAudioFile(audioFile); -} - - -NootiniWindow::~NootiniWindow() -{ - delete m_loader; -} - -//################################################################################################# -//################### PROTECTED ############################################ -//################################################################################################# - -void NootiniWindow::openFileSlot() { - QString audioFileName = QFileDialog::getOpenFileName(this, QString(), m_lastAudioDir, tr("WAV file or raw audio (*.wav *.pcm *.raw)")); - if (!audioFileName.isEmpty()) { - m_lastAudioDir = QFileInfo(audioFileName).absoluteDir().absolutePath(); - processAudioFile(audioFileName); - } -} - - -void NootiniWindow::settingsSlot() { - NootiniSettings sett(&m_tartiniParams, this); - sett.setDrawVolumeChart(m_drawVolume); - sett.setRange(m_loader->pitchRange()); - if (sett.exec() == QDialog::Accepted) { - m_loader->fillTartiniParams(&m_tartiniParams); - m_drawVolume = sett.drawVolumeChart(); - NaudioLoader::setPitchRange(sett.range()); - } -} - - -void NootiniWindow::processAudioFile(const QString& fileName) { - if (m_loader->setAudioFile(fileName)) { - delete m_chart; - m_chart = new Nchart(); - centralWidget()->layout()->addWidget(m_chart); - setWindowTitle("Nootini - " + QFileInfo(fileName).baseName()); - m_againAct->setDisabled(false); - m_toSvgAct->setDisabled(false); - startProcessing(); - } -} - - -void NootiniWindow::processAgain() { - QString fileName = m_loader->fileName(); - delete m_loader; - m_loader = new NaudioLoader(); - if (m_loader->setAudioFile(fileName)) - startProcessing(); -} - - -void NootiniWindow::startProcessing() { - m_loader->fillTartiniParams(&m_tartiniParams); - m_chart->setDrawVolume(m_drawVolume); - m_chart->setAudioLoader(m_loader); - m_loader->startLoading(); -} - - -void NootiniWindow::zoom() { - qreal coef = sender() == m_zoomOutAct ? 0.9375 : 1.0625; - m_chart->scale(coef, coef); -} - - -void NootiniWindow::fitHeight() { - qreal coef = m_chart->viewport()->height() / (m_chart->scene->sceneRect().height() * m_chart->transform().m11()); - m_chart->scale(coef, coef); -} - - -void NootiniWindow::closeEvent(QCloseEvent* e) { - writeConfig(); - QWidget::closeEvent(e); -} - - -void NootiniWindow::resizeEvent(QResizeEvent* e) { - if (e->oldSize().height() > 0) { - double coef = ((double)e->size().height() / (double)e->oldSize().height()); - m_chart->scale(coef, coef); - } - QWidget::resizeEvent(e); -} - - -void NootiniWindow::readConfig() { - Tcore::gl()->config->beginGroup("Tartini"); - m_tartiniParams.threshold = Tcore::gl()->config->value("threshold", 93).toInt(); - m_tartiniParams.doingHarmonicAnalysis = Tcore::gl()->config->value("doingHarmonicAnalysis", false).toBool(); - m_tartiniParams.doingAutoNoiseFloor = Tcore::gl()->config->value("doingAutoNoiseFloor", true).toBool(); - m_tartiniParams.dBFloor = Tcore::gl()->config->value("dBFloor", -150).toDouble(); - m_drawVolume = Tcore::gl()->config->value("drawVolumeChart", true).toBool(); - NaudioLoader::setPitchRange(Tcore::gl()->config->value("pitchRange", 1).toInt()); - m_lastAudioDir = Tcore::gl()->config->value("lastWavDir", QDir::homePath()).toString(); - Tcore::gl()->config->endGroup(); -} - - -void NootiniWindow::writeConfig() { - Tcore::gl()->config->beginGroup("Tartini"); - Tcore::gl()->config->setValue("threshold", m_tartiniParams.threshold); - Tcore::gl()->config->setValue("doingHarmonicAnalysis", m_tartiniParams.doingHarmonicAnalysis); - Tcore::gl()->config->setValue("doingAutoNoiseFloor", m_tartiniParams.doingAutoNoiseFloor); - Tcore::gl()->config->setValue("dBFloor", m_tartiniParams.dBFloor); - Tcore::gl()->config->setValue("drawVolumeChart", m_drawVolume); - Tcore::gl()->config->setValue("pitchRange", NaudioLoader::pitchRange()); - Tcore::gl()->config->setValue("lastWavDir", m_lastAudioDir); - Tcore::gl()->config->endGroup(); -} - - -void NootiniWindow::saveAsSvg() { - QString svgFileName = QFileDialog::getSaveFileName(this, tr("Save chart as SVG image"), - m_loader->fileName().replace(".wav", "", Qt::CaseInsensitive), tr("SVG image (*.svg)")); - if (!svgFileName.isEmpty()) { - QSvgGenerator svgGen; - svgGen.setFileName(svgFileName); - svgGen.setSize(m_chart->scene->sceneRect().size().toSize()); - svgGen.setViewBox(m_chart->scene->sceneRect().toRect()); - svgGen.setTitle(tr("Pitch detection chart of") + " " + m_loader->fileName()); - svgGen.setDescription(tr("Analyze of musical pitch changes in PCM data.")); - QPainter painter( &svgGen ); - m_chart->scene->render(&painter); - } -} - - - diff --git a/tests/nootini/nootiniwindow.h b/tests/nootini/nootiniwindow.h deleted file mode 100644 index 2e6c625b0fa332a55df6b97dc56a7b9ef64cd6c9..0000000000000000000000000000000000000000 --- a/tests/nootini/nootiniwindow.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2015 by Tomasz Bojczuk * - * seelook@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifndef NOOTINIWINDOW_H -#define NOOTINIWINDOW_H - -#include <QtWidgets/QMainWindow> -#include <tartiniparams.h> - -class NaudioLoader; -class QAction; -class Nchart; - -/** - * Main window of Nootini - pitch detection analyzer - */ -class NootiniWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit NootiniWindow(const QString& audioFile = "", QWidget* parent = 0); - virtual ~NootiniWindow(); - -protected: - void readConfig(); /** Reads other settings values than Nootka.conf from Nootini.conf */ - void writeConfig(); /** Writes other settings values to Nootini.conf */ - void startProcessing(); - - virtual void closeEvent(QCloseEvent* e); - virtual void resizeEvent(QResizeEvent* e); - -protected slots: - void openFileSlot(); - void settingsSlot(); - void processAudioFile(const QString& fileName); - void processAgain(); - void zoom(); - void fitHeight(); - void saveAsSvg(); - -private: - Nchart *m_chart; - QAction *m_openAct, *m_settAct, *m_againAct, *m_toSvgAct; - QAction *m_zoomInAct, *m_zoomOutAct, *m_zoomFitAct; - NaudioLoader *m_loader; - TartiniParams m_tartiniParams; - -}; - -#endif // NOOTINIWINDOW_H