void ReplayGain::showResults() { QList<TrackScanner *> okScanners; for (int i=0; i<files.count(); ++i) { TrackScanner *s=scanners[i]; const Track &t=tracks[i]; if (t.success && s->ok()) { printf("TRACK: %d %s %s\n", i, formatDouble(TrackScanner::reference(s->results().loudness)).toLatin1().constData(), formatDouble(s->results().peakValue()).toLatin1().constData()); okScanners.append(s); } else { printf("TRACK: %d FAILED\n", i); } } if (okScanners.isEmpty()) { printf("ALBUM: FAILED\n"); } else { TrackScanner::Data album=TrackScanner::global(okScanners); printf("ALBUM: %s %s\n", formatDouble(TrackScanner::reference(album.loudness)).toLatin1().constData(), formatDouble(album.peak).toLatin1().constData()); } fflush(stdout); QCoreApplication::exit(0); }
bool OutputQtDocument::writeResult() { m_cursor.insertBlock(); m_cursor.insertBlock(); if(SimplexMethod::OptimalSolutionFound == m_params->status() || SimplexMethod::OptimalIntSolutionFound == m_params->status()) { m_cursor.insertHtml(QString("<b>%1</b> "). arg(tr("Optimum is founded:"))); m_cursor.insertBlock(); if(SimplexMethod::OptimizeToMax == m_params->funcType()) m_cursor.insertText(QString("F = %1,").arg(formatDouble(-(m_params->F())))); else m_cursor.insertText(QString("F = %1,").arg(formatDouble(m_params->F()))); m_cursor.insertBlock(); m_cursor.insertText(QString("%1 = (").arg(m_variableName.toUpper())); QStringList plan; for(size_t j=0; j < m_params->width(); j++) { double val = 0.0; for(size_t i = 0; i < m_params->height(); i++) { if(m_params->columnBasis(i) == j) { val = m_params->columnB(i); break; } } plan.push_back(formatDouble(val)); } m_cursor.insertText(plan.join(";")); m_cursor.insertText(")."); m_cursor.insertBlock(); } else if(SimplexMethod::SolutionNotExists == m_params->status()) { m_cursor.insertHtml(QString("<b>%1</b> "). arg(tr("Optimum is not founded."))); } else { m_cursor.insertHtml(QString("<b>%1</b> "). arg(tr("Some error was occured while calculating solution."))); } return true; }
bool OutputQtDocument::writeCanonical() { m_cursor.insertBlock(); m_cursor.insertText(tr("Canonical form of problem is :")); m_cursor.insertBlock(); m_cursor.insertText(QString("F(%1) = ").arg(m_variableName.toUpper())); if(SimplexMethod::OptimizeToMax == m_params->funcType()) m_cursor.insertText("-("); bool firstFlag = true; for(size_t j=0; j < m_params->width(); j++) { if(m_params->variableType(j) == SimplexMethod::VariableArtificial) { putVariable(j, "W", true, firstFlag); } else putVariable(j, m_params->rowC(j), firstFlag); } if(SimplexMethod::OptimizeToMax == m_params->funcType()) m_cursor.insertText(") -> max"); else m_cursor.insertText(" -> min"); // limits for(size_t i=0; i < m_params->height(); i++) { m_cursor.insertBlock(); firstFlag = true; for(size_t j=0; j < m_params->width(); j++) { putVariable(j, m_params->matrixA(i, j), firstFlag); } switch(m_params->columnCompareOp(i)) { case SimplexMethod::Equal: m_cursor.insertText(" = "); break; case SimplexMethod::GreatEqual: m_cursor.insertText(" >= "); break; default: m_cursor.insertText(" <= "); break; } m_cursor.insertText(formatDouble(m_params->columnB(i))); } m_cursor.insertBlock(); m_cursor.insertText(m_variableName); m_cursor.insertText(" >= 0"); m_cursor.insertBlock(); return true; }
char *getData(){ int totmem = totalMemory(); char *TOTAL_MEMORY = formatInt(totmem); float freemem = freeMemory(); float usedmem = usedMemory(); char *FREE_MEMORY = formatFloat(freemem); char *USED_MEMORY = formatFloat(usedmem); double loadavg[1]; getloadavg(loadavg, 1); char *CPU_LOAD_AVG = formatDouble(loadavg[0] * 10); double cpuLoad = getCpuReading(); char *CPU_LOAD_CURR = formatDouble(cpuLoad); double cpuTemp = getCpuTemp(); char *CPU_TEMP = formatDouble(cpuTemp); char host[40];//cuts username off if more than 40 characters. gethostname(host, sizeof(host)); char HOSTNAME[40] ="|"; strcat(HOSTNAME,host); int hostlen = strlen(HOSTNAME); for (int s = hostlen; s <40; s++){//fill excess space to prevent overflows. strcpy(&HOSTNAME[s], " "); } char *data = new char[75]; //original 35 strcpy(data,HOSTNAME); strcat(data,TOTAL_MEMORY); strcat(data,FREE_MEMORY); strcat(data,USED_MEMORY); strcat(data,CPU_LOAD_AVG); strcat(data,CPU_LOAD_CURR); strcat(data,CPU_TEMP); return data; }
void Sword25FileProxy::setupConfigFile() { double sfxVolume = !ConfMan.hasKey("sfx_volume") ? 1.0 : 1.0 * ConfMan.getInt("sfx_volume") / 255.0; double musicVolume = !ConfMan.hasKey("music_volume") ? 0.5 : 1.0 * ConfMan.getInt("music_volume") / 255.0; double speechVolume = !ConfMan.hasKey("speech_volume") ? 1.0 : 1.0 * ConfMan.getInt("speech_volume") / 255.0; bool subtitles = !ConfMan.hasKey("subtitles") ? true : ConfMan.getBool("subtitles"); _readData = Common::String::format( "GAME_LANGUAGE = \"%s\"\r\n\ GAME_SUBTITLES = %s\r\n\ MAX_MEMORY_USAGE = 256000000\r\n\ GFX_VSYNC_ACTIVE = true\r\n\ SFX_SAMPLING_RATE = 44100\r\n\ SFX_CHANNEL_COUNT = 32\r\n\ SFX_SOUND_VOLUME = %s\r\n\ SFX_MUSIC_VOLUME = %s\r\n\ SFX_SPEECH_VOLUME = %s\r\n", getLanguage().c_str(), subtitles ? "true" : "false", formatDouble(sfxVolume).c_str(), formatDouble(musicVolume).c_str(), formatDouble(speechVolume).c_str()); _readPos = 0; }
char *formatSize(unsigned long int bytes) { double dbytes = (double) bytes; char *postfix[] = {" байт", " кб", " Мб", " Гб", " Тб"}; unsigned short int step = 0; while(dbytes > 1024) { dbytes /= 1024; ++ step; } char *left = formatDouble(dbytes); char *result = concat(left, postfix[step]); free(left); return result; }
void OutputQtDocument::putVariable(int index, double multiplier, bool &firstFlag) { if(!m_params->checkEquals(multiplier, 0.0)) { if(firstFlag) { if(multiplier < 0) m_cursor.insertText("-"); if(std::abs(multiplier) != 1.0) { m_cursor.insertText(formatDouble(std::abs(multiplier))); // m_cursor.insertText(QChar(0x2027)); } firstFlag = false; } else { if(multiplier > 0) m_cursor.insertText(" + "); else m_cursor.insertText(" - "); if(std::abs(multiplier) != 1.0) { m_cursor.insertText(formatDouble(std::abs(multiplier))); // m_cursor.insertText(QChar(0x2027)); } } m_cursor.insertHtml(QString("%1<sub>%2</sub> "). arg(m_variableName). arg(index+1)); } }
std::string DictionaryLuaFormatter::formatValue(const Dictionary& dictionary, const std::string& key, int indentationSteps) const { const char* whitespace = _prettyPrint ? " " : ""; if (dictionary.hasValue<Dictionary>(key)) { Dictionary subDictionary = dictionary.value<Dictionary>(key); return format(subDictionary, indentationSteps); } if (dictionary.hasValue<glm::dvec4>(key)) { glm::dvec4 vec = dictionary.value<glm::dvec4>(key); return "{" + formatDouble(vec.x) + "," + formatDouble(vec.y) + "," + whitespace + formatDouble(vec.z) + "," + whitespace + formatDouble(vec.w) + "}"; } if (dictionary.hasValue<glm::dvec3>(key)) { glm::dvec3 vec = dictionary.value<glm::dvec3>(key); return "{" + formatDouble(vec.x) + "," + whitespace + formatDouble(vec.y) + "," + whitespace + formatDouble(vec.z) + "}"; } if (dictionary.hasValue<glm::dvec2>(key)) { glm::dvec2 vec = dictionary.value<glm::dvec2>(key); return "{" + formatDouble(vec.x) + "," + whitespace + formatDouble(vec.y) + "}"; } if (dictionary.hasValue<double>(key)) { double value = dictionary.value<double>(key); return formatDouble(value); } if (dictionary.hasValue<int>(key)) { int value = dictionary.value<int>(key); return std::to_string(value); } if (dictionary.hasValue<std::string>(key)) { std::string value = dictionary.value<std::string>(key); std::string luaString; for (const char& c : value) { switch (c) { case '"': luaString += "\\\""; break; case '\\': luaString += "\\\\"; break; case '\b': luaString += "\\b"; break; case '\f': luaString += "\\f"; break; case '\n': luaString += "\\n"; break; case '\r': luaString += "\\r"; break; case '\t': luaString += "\\t"; break; default: luaString += c; } } return "\"" + luaString + "\""; } throw LuaFormattingError( "Key '" + key + "' has invalid type for formatting dictionary as lua" ); }
bool OutputQtDocument::writeStability() { m_cursor.insertBlock(); m_cursor.insertHtml(QString("</b>%1</b> "). arg(tr("Stability conditions:"))); for(size_t i=0; i < m_params->height(); i++) { if(m_params->limitType(i) != SimplexMethod::LimitMain) continue; SimplexMethod::Interval ival = m_params->stabilityColumnB(i); m_cursor.insertBlock(); m_cursor.insertHtml(QString("B<sub>%1</sub> ").arg(i+1)); m_cursor.insertText(QChar(0x220A)); m_cursor.insertText(" "); if(ival.start() == -std::numeric_limits<double>::infinity()) m_cursor.insertText(QString("(-")+QChar(0x221E)); else { m_cursor.insertText("["); m_cursor.insertText(formatDouble(ival.start())); } m_cursor.insertText(" ; "); if(ival.end() == std::numeric_limits<double>::infinity()) m_cursor.insertText(QChar(0x221E)+QString(")")); else { m_cursor.insertText(formatDouble(ival.end())); m_cursor.insertText("]"); } } m_cursor.insertBlock(); for(size_t j=0; j < m_params->width(); j++) { if(m_params->variableType(j) != SimplexMethod::VariableMain) continue; SimplexMethod::Interval ival = m_params->stabilityRowC(j); m_cursor.insertBlock(); m_cursor.insertHtml(QString("C<sub>%1</sub> ").arg(j+1)); m_cursor.insertText(QChar(0x220A)); m_cursor.insertText(" "); if(ival.start() == -std::numeric_limits<double>::infinity()) m_cursor.insertText(QString("(-")+QChar(0x221E)); else { m_cursor.insertText("["); m_cursor.insertText(formatDouble(ival.start())); } m_cursor.insertText(" ; "); if(ival.end() == std::numeric_limits<double>::infinity()) m_cursor.insertText(QChar(0x221E)+QString(")")); else { m_cursor.insertText(formatDouble(ival.end())); m_cursor.insertText("]"); } } return true; }
bool OutputQtDocument::writeTable() { /* start of table */ m_cursor.beginEditBlock(); m_cursor.insertBlock(); m_cursor.insertBlock(); QTextFrame *topFrame = m_cursor.currentFrame(); QTextTableFormat tableFormat; tableFormat.setCellPadding(4); tableFormat.setHeaderRowCount(1); /* tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Double); */ tableFormat.setMargin(2); tableFormat.setWidth(QTextLength( QTextLength::PercentageLength, 100)); QTextTable *table = m_cursor.insertTable( m_params->height()+2, m_params->width()+5, tableFormat); /* headers */ m_cursor = table->cellAt(0, 0).firstCursorPosition(); m_cursor.insertText("i"); m_cursor = table->cellAt(0, 1).firstCursorPosition(); m_cursor.insertText(tr("basis")); m_cursor = table->cellAt(0, 2).firstCursorPosition(); m_cursor.insertHtml("C<sub>i</sub> "); m_cursor = table->cellAt(0, 3).firstCursorPosition(); m_cursor.insertText("B"); for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(0, j+4).firstCursorPosition(); m_cursor.insertHtml(QString("P<sub>%1</sub> ").arg(j+1)); /* m_cursor.insertHtml(QString("C<sub>%1</sub> =").arg(j+1)); if(m_params->variableType(j) == SimplexMethod::VariableArtificial) m_cursor.insertText("W"); else m_cursor.insertText(formatDouble(m_params->rowC(j))); */ } m_cursor = table->cellAt(0, m_params->width()+4).firstCursorPosition(); m_cursor.insertText(QChar(0x0398)); // theta /* matrix, columnCompareOp, columnB, columnTheta */ for(size_t i=0; i < m_params->height(); i++) { m_cursor = table->cellAt(i+1, 0).firstCursorPosition(); m_cursor.insertText(QString("%1").arg(i+1)); // basis m_cursor = table->cellAt(i+1, 1).firstCursorPosition(); size_t basisColumn = m_params->columnBasis(i); m_cursor.insertHtml(QString("P<sub>%1</sub> ").arg(basisColumn+1)); // basis C m_cursor = table->cellAt(i+1, 2).firstCursorPosition(); if(m_params->variableType(basisColumn) == SimplexMethod::VariableArtificial) m_cursor.insertText("W"); else m_cursor.insertText(formatDouble(m_params->rowC(basisColumn))); // B m_cursor = table->cellAt(i+1, 3).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->columnB(i))); // matrix for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(i+1, j+4).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->matrixA(i, j))); } // theta m_cursor = table->cellAt(i+1, m_params->width()+4).firstCursorPosition(); if(m_params->columnTheta(i) > 0) m_cursor.insertText(formatDouble(m_params->columnTheta(i))); else m_cursor.insertText("-"); } /* m+1 row */ m_cursor = table->cellAt(m_params->height()+1, 0).firstCursorPosition(); m_cursor.insertText("m+1"); m_cursor = table->cellAt(m_params->height()+1, 3).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->F())); for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(m_params->height()+1, j+4).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->rowD(j))); } /* m+2 row (for artificial variables) */ if(m_params->artificialFlag()) { table->appendRows(1); m_cursor = table->cellAt(m_params->height()+2, 0).firstCursorPosition(); m_cursor.insertText("m+2"); m_cursor = table->cellAt(m_params->height()+2, 3).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->WF())); for(size_t j=0; j < m_params->width(); j++) { m_cursor = table->cellAt(m_params->height()+2, j+4).firstCursorPosition(); m_cursor.insertText(formatDouble(m_params->rowWD(j))); } } /* end of table */ m_cursor.endEditBlock(); m_cursor.setPosition(topFrame->lastPosition()); return true; }