From 0e6355329f241a3e3c8b38cb4146fda4470e6ed0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 26 Mar 2018 15:33:06 -0400 Subject: Whitespace changes --- generator/database.cpp | 14 ++++++------- generator/database.h | 2 +- generator/field.h | 12 +++++------ generator/generator.cpp | 56 ++++++++++++++++++++++++------------------------- generator/generator.h | 36 +++++++++++++++---------------- generator/main.cpp | 2 +- generator/mood.cpp | 42 ++++++++++++++++++------------------- generator/mood.h | 22 +++++++++---------- generator/progress.h | 16 +++++++------- 9 files changed, 101 insertions(+), 101 deletions(-) (limited to 'generator') diff --git a/generator/database.cpp b/generator/database.cpp index f326f46..b46a0d1 100644 --- a/generator/database.cpp +++ b/generator/database.cpp @@ -73,19 +73,19 @@ namespace cadence { { sqlite3_close_v2(ppdb_); } - + void database::runQuery(std::string query) { // This can only happen when doing bad things with move semantics. assert(ppdb_ != nullptr); - + sqlite3_stmt* ppstmt; if (sqlite3_prepare_v2(ppdb_, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) { throw sqlite3_error("Error writing to database", sqlite3_errmsg(ppdb_)); } - + int result = sqlite3_step(ppstmt); sqlite3_finalize(ppstmt); @@ -99,10 +99,10 @@ namespace cadence { { // This can only happen when doing bad things with move semantics. assert(ppdb_ != nullptr); - + // This shouldn't happen. assert(!fields.empty()); - + std::list fieldNames; std::list qs; for (field& f : fields) @@ -110,7 +110,7 @@ namespace cadence { fieldNames.push_back(f.getName()); qs.push_back("?"); } - + std::ostringstream query; query << "INSERT INTO "; query << table; @@ -119,7 +119,7 @@ namespace cadence { query << ") VALUES ("; query << implode(std::begin(qs), std::end(qs), ", "); query << ")"; - + std::string query_str = query.str(); sqlite3_stmt* ppstmt; diff --git a/generator/database.h b/generator/database.h index 7aa8dfa..e4f3ba2 100644 --- a/generator/database.h +++ b/generator/database.h @@ -52,7 +52,7 @@ namespace cadence { ~database(); // Actions - + void runQuery(std::string query); void insertIntoTable(std::string table, std::list fields); diff --git a/generator/field.h b/generator/field.h index 9d6ed9a..836c079 100644 --- a/generator/field.h +++ b/generator/field.h @@ -32,27 +32,27 @@ namespace cadence { ~field(); // Generic accessors - + type getType() const { return type_; } - + std::string getName() const { return name_; } // Integer - + field(std::string name, int arg); - + int getInteger() const; // String - + field(std::string name, std::string arg); - + std::string getString() const; private: diff --git a/generator/generator.cpp b/generator/generator.cpp index eb2750c..54f5d69 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp @@ -11,7 +11,7 @@ namespace cadence { namespace generator { - + generator::generator( std::string inputpath, std::string outputpath) : @@ -23,23 +23,23 @@ namespace cadence { { inputpath_ += '/'; } - + inputpath_ += "highlevel/"; } - + void generator::run() { // Creates the datafile. writeSchema(); - + // Scans the AcousticBrainz data dump and generates a list of all of the // files in the dump. scanDirectories(); - + // Parses each data file and enters it into the database. parseData(); } - + void generator::writeSchema() { std::ifstream file("schema.sql"); @@ -47,7 +47,7 @@ namespace cadence { { throw std::invalid_argument("Could not find database schema"); } - + std::ostringstream schemaBuilder; std::string line; while (std::getline(file, line)) @@ -56,10 +56,10 @@ namespace cadence { { line.pop_back(); } - + schemaBuilder << line; } - + std::string schema = schemaBuilder.str(); auto queries = split>(schema, ";"); progress ppgs("Writing database schema...", queries.size()); @@ -69,73 +69,73 @@ namespace cadence { { db_.runQuery(query); } - + ppgs.update(); } } - + void generator::scanDirectories() { std::cout << "Scanning AcousticBrainz dump..." << std::endl; - + DIR* topdir; if ((topdir = opendir(inputpath_.c_str())) == nullptr) { throw std::invalid_argument("Invalid AcousticBrainz data directory"); } - + struct dirent* topent; while ((topent = readdir(topdir)) != nullptr) { if (topent->d_name[0] != '.') { std::string directory = inputpath_ + topent->d_name + "/"; - + DIR* subdir; if ((subdir = opendir(directory.c_str())) == nullptr) { throw std::invalid_argument("Invalid AcousticBrainz data directory"); } - + struct dirent* subent; while ((subent = readdir(subdir)) != nullptr) { if (subent->d_name[0] != '.') { std::string subdirectory = directory + subent->d_name + "/"; - + DIR* subsubdir; if ((subsubdir = opendir(subdirectory.c_str())) == nullptr) { throw std::invalid_argument("Invalid AcousticBrainz data directory"); } - + struct dirent* subsubent; while ((subsubent = readdir(subsubdir)) != nullptr) { if (subsubent->d_name[0] != '.') { std::string datafile = subdirectory + subsubent->d_name; - + datafiles_.push_back(datafile); } } - + closedir(subsubdir); } } - + closedir(subdir); } } - + closedir(topdir); } - + void generator::parseData() { progress ppgs("Parsing AcousticBrainz data files...", datafiles_.size()); - + for (std::string datafile : datafiles_) { ppgs.update(); @@ -145,7 +145,7 @@ namespace cadence { std::ifstream dataStream(datafile); dataStream >> jsonData; } - + try { std::vector moods; @@ -158,16 +158,16 @@ namespace cadence { moods.emplace_back(mood::type::relaxed, jsonData["highlevel"]["mood_relaxed"]["all"]["relaxed"]); moods.emplace_back(mood::type::sad, jsonData["highlevel"]["mood_sad"]["all"]["sad"]); moods.emplace_back(mood::type::instrumental, jsonData["highlevel"]["voice_instrumental"]["all"]["instrumental"]); - + std::sort(std::begin(moods), std::end(moods), [] (const mood& left, const mood& right) -> bool { return left.getProbability() > right.getProbability(); }); - + std::list fields; fields.emplace_back("title", jsonData["metadata"]["tags"]["title"][0].get()); fields.emplace_back("artist", jsonData["metadata"]["tags"]["artist"][0].get()); fields.emplace_back("category", moods.front().getCategory()); - + db_.insertIntoTable("songs", std::move(fields)); } catch (const std::domain_error& ex) { @@ -175,6 +175,6 @@ namespace cadence { } } } - + }; }; diff --git a/generator/generator.h b/generator/generator.h index d911c61..dff8eeb 100644 --- a/generator/generator.h +++ b/generator/generator.h @@ -7,44 +7,44 @@ namespace cadence { namespace generator { - + class generator { public: - + // Constructor - + generator( std::string inputpath, std::string outputpath); - + // Action - + void run(); - + // Subroutines - + void writeSchema(); - + void scanDirectories(); - + void parseData(); - + private: - + // Input - + std::string inputpath_; - + // Output - + database db_; - + // Cache - + std::list datafiles_; - + }; - + }; }; diff --git a/generator/main.cpp b/generator/main.cpp index 5a3d2dd..318770e 100644 --- a/generator/main.cpp +++ b/generator/main.cpp @@ -16,7 +16,7 @@ int main(int argc, char** argv) try { cadence::generator::generator app(argv[1], argv[2]); - + try { app.run(); diff --git a/generator/mood.cpp b/generator/mood.cpp index 9f53dce..b74211c 100644 --- a/generator/mood.cpp +++ b/generator/mood.cpp @@ -2,7 +2,7 @@ namespace cadence { namespace generator { - + // The categories are: // - party (+danceable, -acoustic, +electronic, +party) = ~.21 // - chill (-danceable, +acoustic, -aggressive, -electronic, -party, +relaxed) = ~.49 @@ -11,7 +11,7 @@ namespace cadence { // - sad (-happy, +sad) = ~.02 // - instrumental (+instrumental) = ~.12 // - vocal (-instrumental) = ~.10 - + mood::mood(type t, double prob) : type_(t) { if (prob >= 0.5) @@ -22,73 +22,73 @@ namespace cadence { probability_ = 1.0 - prob; positive_ = false; } - + switch (t) { case type::danceable: { category_ = (positive_ ? "party" : "chill"); - + break; } - + case type::acoustic: { category_ = (positive_ ? "chill" : "party"); - + break; } - + case type::aggressive: { category_ = (positive_ ? "crazy" : "chill"); - + break; } - + case type::electronic: { category_ = (positive_ ? "party" : "chill"); - + break; } - + case type::happy: { category_ = (positive_ ? "happy" : "sad"); - + break; } - + case type::party: { category_ = (positive_ ? "party" : "chill"); - + break; } - + case type::relaxed: { category_ = (positive_ ? "chill" : "crazy"); - + break; } - + case type::sad: { category_ = (positive_ ? "sad" : "happy"); - + break; } - + case type::instrumental: { category_ = (positive_ ? "instrumental" : "vocal"); - + break; } } } - + }; }; diff --git a/generator/mood.h b/generator/mood.h index df5d28f..c36e5ee 100644 --- a/generator/mood.h +++ b/generator/mood.h @@ -5,7 +5,7 @@ namespace cadence { namespace generator { - + class mood { public: enum class type { @@ -19,41 +19,41 @@ namespace cadence { sad, instrumental }; - + // Constructor - + mood(type t, double prob); - + // Accessors - + type getType() const { return type_; } - + double getProbability() const { return probability_; } - + bool getPositive() const { return positive_; } - + std::string getCategory() const { return category_; } - + private: type type_; double probability_; bool positive_; std::string category_; - + }; - + }; }; diff --git a/generator/progress.h b/generator/progress.h index f42f701..e5cc13d 100644 --- a/generator/progress.h +++ b/generator/progress.h @@ -5,20 +5,20 @@ namespace cadence { namespace generator { - + class progress { private: std::string message; int total; int cur = 0; int lprint = 0; - + public: progress(std::string message, int total) : message(message), total(total) { std::cout << message << " 0%" << std::flush; } - + void update(int val) { if (val <= total) @@ -27,29 +27,29 @@ namespace cadence { } else { cur = total; } - + int pp = cur * 100 / total; if (pp != lprint) { lprint = pp; - + std::cout << "\b\b\b\b" << std::right; std::cout.width(3); std::cout << pp << "%" << std::flush; } } - + void update() { update(cur+1); } - + ~progress() { std::cout << "\b\b\b\b100%" << std::endl; } }; - + }; }; -- cgit 1.4.1