diff --git a/src/plugins/csoundsoundcontroller/csengine.cpp b/src/plugins/csoundsoundcontroller/csengine.cpp index a0c7f94..5a44ced 100644 --- a/src/plugins/csoundsoundcontroller/csengine.cpp +++ b/src/plugins/csoundsoundcontroller/csengine.cpp @@ -1,61 +1,62 @@ /**************************************************************************** ** ** Copyright (C) 2016 by Sandro S. Andrade ** ** 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 2 of ** the License or (at your option) version 3 or any later version ** accepted by the membership of KDE e.V. (or its successor approved ** by the membership of KDE e.V.), which shall act as a proxy ** defined in Section 14 of version 3 of the license. ** ** 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 . ** ****************************************************************************/ #include "csengine.h" #include #include #include #include #include #include CsEngine::CsEngine() { m_fileName = (char *)"./template.csd"; } void CsEngine::run() { cs.setOpenSlCallbacks(); // for android audio to work QFile file(m_fileName); file.open(QIODevice::ReadOnly); qDebug() << "Template: "; - while (!file.atEnd()) + while (!file.atEnd()) { qDebug() << file.readLine(); + } file.close(); qWarning() << "Dir " << QDir::currentPath() << " contains sf_GMbank.sf2? " << QDir::current().entryList(QDir::Files).contains("sf_GMbank.sf2"); qWarning() << "Dir " << QCoreApplication::applicationDirPath() << " contains libfluidOpcodes.so? " << QDir(QCoreApplication::applicationDirPath()).entryList(QDir::Files).contains("libfluidOpcodes.so"); qDebug() << "READING " << QDir::currentPath() + "/template.csd"; qDebug() << "SOUNDFONT EXISTS? " << QFile("/data/data/org.kde.minuet/files/sf_GMbank.sf2").exists() << " " << QFileInfo("/data/data/org.kde.minuet/files/sf_GMbank.sf2").size() << "b"; if (cs.Compile(m_fileName)) { cs.Start(); cs.Perform(); cs.Cleanup(); cs.Reset(); cs.Stop(); } } void CsEngine::stop() { // cs.Stop(); } diff --git a/src/plugins/csoundsoundcontroller/csoundsoundcontroller.cpp b/src/plugins/csoundsoundcontroller/csoundsoundcontroller.cpp index 9edcd6d..ef41d45 100644 --- a/src/plugins/csoundsoundcontroller/csoundsoundcontroller.cpp +++ b/src/plugins/csoundsoundcontroller/csoundsoundcontroller.cpp @@ -1,234 +1,236 @@ /**************************************************************************** ** ** Copyright (C) 2016 by Sandro S. Andrade ** ** 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 2 of ** the License or (at your option) version 3 or any later version ** accepted by the membership of KDE e.V. (or its successor approved ** by the membership of KDE e.V.), which shall act as a proxy ** defined in Section 14 of version 3 of the license. ** ** 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 . ** ****************************************************************************/ #include "csoundsoundcontroller.h" #include "csengine.h" #include #include #include Q_DECLARE_LOGGING_CATEGORY(MINUETANDROID) CsoundSoundController::CsoundSoundController(QObject *parent): Minuet::ISoundController(parent), m_csoundEngine(new CsEngine) { qmlRegisterType("org.kde.minuet", 1, 0, "CsoundSoundController"); openExerciseFile(); // setQuestionLabel("new question"); } void CsoundSoundController::openExerciseFile() { QStringList templateList; templateList.append(QStringLiteral("assets:/share/template.csd")); // templateList.append(QStringLiteral("assets:/share/template_rhythm.csd")); qDebug() << "DIRPATH: " << QCoreApplication::applicationDirPath(); qDebug() << "ASSETSPATH: " << QDir("assets:/").canonicalPath(); qDebug() << "QStandardPaths::ApplicationsLocation: " << QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation); qDebug() << "QStandardPaths::GenericDataLocation: " << QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); qDebug() << "QStandardPaths::AppDataLocation: " << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); qDebug() << "QStandardPaths::AppLocalDataLocation: " << QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation); qDebug() << "QStandardPaths::AppConfigLocation: " << QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation); QDir appDir(QCoreApplication::applicationDirPath()); qDebug() << "Contains libfluidOpcodes.so? " << appDir.entryList(QDir::Files).contains("libfluidOpcodes.so"); qDebug() << "DIRPATH: " << appDir << " Contents: " << appDir.entryList(QDir::AllEntries); appDir.cdUp(); qDebug() << "DIRPATH: " << appDir << " Contents: " << appDir.entryList(QDir::AllEntries); appDir.cdUp(); qDebug() << "DIRPATH: " << appDir << " Contents: " << appDir.entryList(QDir::AllEntries); QDir reserved("/data/data/org.kde.minuet/qt-reserved-files/"); qDebug() << "RESERVED: " << reserved << " Contents: " << reserved.entryList(QDir::AllEntries); QDirIterator it("/", QDirIterator::Subdirectories); - while (it.hasNext()) + while (it.hasNext()) { qDebug() << "FILE: " << it.next(); + } foreach (const QString &templateString, templateList) { QFile sfile(templateString); - if (!sfile.open(QIODevice::ReadOnly | QIODevice::Text)) + if (!sfile.open(QIODevice::ReadOnly | QIODevice::Text)) { return; + } QTextStream in(&sfile); QString lineData; QString tempBeginLine; QString tempEndLine; while (!in.atEnd()) { lineData = in.readLine(); lineData.replace("APPDIRPATH", QCoreApplication::applicationDirPath()); tempBeginLine = tempBeginLine + lineData + '\n'; if (lineData.contains("")) { m_begLine.append(tempBeginLine); break; } } while (!in.atEnd()) { lineData = in.readLine(); tempEndLine += lineData + '\n'; } m_endLine.append(tempEndLine); } qDebug() << "m_begLine: " << m_begLine; qDebug() << "m_endLine: " << m_endLine; } void CsoundSoundController::appendEvent(QList midiNotes, QList barStartInfo, QString playMode) { //TODO : use grantlee processing or any other text template library int templateNumber = playMode == "rhythm" ? 1:0; QString content; QString fifthParam = QStringLiteral("100"); QFile m_csdFileOpen(QStringLiteral("./template.csd")); qDebug() << "CREATING " << QDir::currentPath() + "/template.csd"; - if(!m_csdFileOpen.isOpen()) { + if (!m_csdFileOpen.isOpen()) { m_csdFileOpen.open(QIODevice::ReadWrite | QIODevice::Text); } m_csdFileOpen.resize(0); if (playMode == "rhythm") { QString wave = QStringLiteral("f 1 0 16384 10 1\n\n"); content += wave; fifthParam = QStringLiteral(""); } - for(int i=0; i midiNotes; QList barStartInfo; if (m_playMode == "rhythm") { - for(int k = 0; k < 4; ++k) { + for (int k = 0; k < 4; ++k) { midiNotes.append(80); barStartInfo.append(barStart++); } } int exerciseOptionsSize = selectedExerciseOptions.size(); for (int i = 0; i < exerciseOptionsSize; ++i) { QString sequence = selectedExerciseOptions[i].toObject()[QStringLiteral("sequence")].toString(); unsigned int chosenRootNote = selectedExerciseOptions[i].toObject()[QStringLiteral("rootNote")].toString().toInt(); if (m_playMode != "rhythm") { midiNotes.append(chosenRootNote); barStartInfo.append(barStart); unsigned int j = 1; foreach(const QString &additionalNote, sequence.split(' ')) { - midiNotes.append(chosenRootNote+additionalNote.toInt()); + midiNotes.append(chosenRootNote + additionalNote.toInt()); barStartInfo.append((m_playMode == "scale") ? barStart+j:barStart); ++j; } barStart++; } else { midiNotes.append(80); barStartInfo.append(barStart); foreach(QString additionalNote, sequence.split(' ')) { // krazy:exclude=foreach midiNotes.append(37); barStartInfo.append(barStart); float dotted = 1; if (additionalNote.endsWith('.')) { dotted = 1.5; additionalNote.chop(1); } barStart += dotted*1*(4.0/additionalNote.toInt()); } } } if (m_playMode == "rhythm") { midiNotes.append(80); barStartInfo.append(barStart); } appendEvent(midiNotes, barStartInfo, m_playMode); } void CsoundSoundController::prepareFromMidiFile(const QString &fileName) { Q_UNUSED(fileName) } void CsoundSoundController::play() { m_csoundEngine->start(); setState(PlayingState); } void CsoundSoundController::pause() { } void CsoundSoundController::stop() { m_csoundEngine->stop(); setState(StoppedState); } void CsoundSoundController::reset() { } void CsoundSoundController::setPitch (qint8 pitch) { Q_UNUSED(pitch) } void CsoundSoundController::setVolume (quint8 volume) { Q_UNUSED(volume) } void CsoundSoundController::setTempo (quint8 tempo) { Q_UNUSED(tempo) } //#include "moc_csoundsoundcontroller.cpp"