Permalink
Browse files

Quick singleton

  • Loading branch information...
1 parent c956d45 commit b8107edfaf59f6c129ebdc04d5affc38e88a96b3 @ibsh committed Mar 30, 2012
Showing with 109 additions and 8 deletions.
  1. +2 −2 asynckeyprocess.cpp
  2. +1 −0 asynckeyprocess.h
  3. +4 −4 asynckeyresult.h
  4. +1 −0 guibatch.cpp
  5. +4 −2 is_KeyFinder.pro
  6. +21 −0 keyfinderapplication.cpp
  7. +39 −0 libkeyfindersingleton.cpp
  8. +37 −0 libkeyfindersingleton.h
View
@@ -64,8 +64,8 @@ KeyFinderResultWrapper keyDetectionProcess(const AsyncFileObject& object){
delete ds;
}
- static KeyFinder::KeyFinder keyFinder; // static because it retains useful resources between uses
- result.core = keyFinder.findKey(*audio, object.prefs.core);
+ KeyFinder::KeyFinder* kf = LibKeyFinderSingleton::getInstance()->getKeyFinder();
+ result.core = kf->findKey(*audio, object.prefs.core);
delete audio;
View
@@ -37,6 +37,7 @@
#include "downsampler.h"
#include "asyncfileobject.h"
#include "asynckeyresult.h"
+#include "libkeyfindersingleton.h"
// trying this as a global function rather than an object...
KeyFinderResultWrapper keyDetectionProcess(const AsyncFileObject&);
View
@@ -19,10 +19,10 @@
*************************************************************************/
-#ifndef KeyDetectionResult_H
-#define KeyDetectionResult_H
+#ifndef KEYFINDERRESULTWRAPPER_H
+#define KEYFINDERRESULTWRAPPER_H
-#include <QObject>
+#include <QString>
#include "keyfinder/keyfinderresult.h"
class KeyFinderResultWrapper{
@@ -32,4 +32,4 @@ class KeyFinderResultWrapper{
QString errorMessage;
};
-#endif // KeyDetectionResult_H
+#endif // KEYFINDERRESULTWRAPPER_H
View
@@ -141,6 +141,7 @@ BatchWindow::BatchWindow(MainMenuHandler* handler, QWidget* parent) : QMainWindo
// VALGRIND
// QList<QUrl> test;
// test.push_back(QUrl("/Users/ibrahimshaath/Desktop/test tracks"));
+// test.push_back(QUrl("/Users/shaati01/QtProjects/is_KeyFinder_supt/test tracks"));
// receiveUrls(test);
}
View
@@ -44,7 +44,8 @@ SOURCES += \
os_windows.cpp \
asyncfileobject.cpp \
externalplaylist.cpp \
- externalplaylistserato.cpp
+ externalplaylistserato.cpp \
+ libkeyfindersingleton.cpp
HEADERS += \
decoderlibav.h \
@@ -84,7 +85,8 @@ HEADERS += \
_VERSION.h \
asyncfileobject.h \
externalplaylist.h \
- externalplaylistserato.h
+ externalplaylistserato.h \
+ libkeyfindersingleton.h
FORMS += \
detailwindow.ui \
View
@@ -1,3 +1,24 @@
+/*************************************************************************
+
+ Copyright 2011 Ibrahim Sha'ath
+
+ This file is part of KeyFinder.
+
+ KeyFinder 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.
+
+ KeyFinder 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 KeyFinder. If not, see <http://www.gnu.org/licenses/>.
+
+*************************************************************************/
+
#include "keyfinderapplication.h"
KeyFinderApplication::KeyFinderApplication(int& a, char**& b) : QApplication(a,b){ }
View
@@ -0,0 +1,39 @@
+/*************************************************************************
+
+ Copyright 2011 Ibrahim Sha'ath
+
+ This file is part of KeyFinder.
+
+ KeyFinder 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.
+
+ KeyFinder 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 KeyFinder. If not, see <http://www.gnu.org/licenses/>.
+
+*************************************************************************/
+
+#include "libkeyfindersingleton.h"
+
+LibKeyFinderSingleton* LibKeyFinderSingleton::inst = NULL;
+
+QMutex singletonMutex;
+
+LibKeyFinderSingleton* LibKeyFinderSingleton::getInstance(){
+ QMutexLocker locker(&singletonMutex);
+ if(inst == NULL)
+ inst = new LibKeyFinderSingleton();
+ return inst;
+}
+
+LibKeyFinderSingleton::LibKeyFinderSingleton(){ }
+
+KeyFinder::KeyFinder* LibKeyFinderSingleton::getKeyFinder(){
+ return &kf;
+}
View
@@ -0,0 +1,37 @@
+/*************************************************************************
+
+ Copyright 2011 Ibrahim Sha'ath
+
+ This file is part of KeyFinder.
+
+ KeyFinder 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.
+
+ KeyFinder 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 KeyFinder. If not, see <http://www.gnu.org/licenses/>.
+
+*************************************************************************/
+
+#ifndef LIBKEYFINDERSINGLETON_H
+#define LIBKEYFINDERSINGLETON_H
+#include <QMutex>
+#include "keyfinder/keyfinder.h"
+
+class LibKeyFinderSingleton{
+public:
+ static LibKeyFinderSingleton* getInstance();
+ KeyFinder::KeyFinder* getKeyFinder();
+private:
+ LibKeyFinderSingleton();
+ static LibKeyFinderSingleton* inst;
+ KeyFinder::KeyFinder kf;
+};
+
+#endif // LIBKEYFINDERSINGLETON_H

0 comments on commit b8107ed

Please sign in to comment.