Ban `long` from codebase. Use int64_t instead.tags/v2.0.0
@@ -37,11 +37,11 @@ struct Engine { | |||||
void yieldWorkers(); | void yieldWorkers(); | ||||
/** Returns the number of audio samples since the Engine's first sample. | /** Returns the number of audio samples since the Engine's first sample. | ||||
*/ | */ | ||||
long getFrame(); | |||||
int64_t getFrame(); | |||||
/** Returns the frame when step() was last called. */ | /** Returns the frame when step() was last called. */ | ||||
long getStepFrame(); | |||||
int64_t getStepFrame(); | |||||
/** Returns the timestamp in nanoseconds when step() was last called. */ | /** Returns the timestamp in nanoseconds when step() was last called. */ | ||||
long getStepTime(); | |||||
int64_t getStepTime(); | |||||
/** Returns the total number of frames in the current step() call. */ | /** Returns the total number of frames in the current step() call. */ | ||||
int getStepFrames(); | int getStepFrames(); | ||||
@@ -18,7 +18,7 @@ struct Message { | |||||
/** Initialized to 3 empty bytes. */ | /** Initialized to 3 empty bytes. */ | ||||
std::vector<uint8_t> bytes; | std::vector<uint8_t> bytes; | ||||
/** Timestamp of MIDI message in nanoseconds. Negative if not set. */ | /** Timestamp of MIDI message in nanoseconds. Negative if not set. */ | ||||
long timestamp = -1; | |||||
int64_t timestamp = -1; | |||||
Message() : bytes(3) {} | Message() : bytes(3) {} | ||||
@@ -36,10 +36,10 @@ int getLogicalCoreCount(); | |||||
void setThreadName(const std::string& name); | void setThreadName(const std::string& name); | ||||
/** Returns the caller's human-readable stack trace with "\n"-separated lines. */ | /** Returns the caller's human-readable stack trace with "\n"-separated lines. */ | ||||
std::string getStackTrace(); | std::string getStackTrace(); | ||||
/** Returns the current number of nanoseconds since the epoch. | |||||
Currently uses std::chrono::high_resolution_clock. | |||||
/** Returns the current number of nanoseconds since the epoch with the highest precion available on the OS. | |||||
The epoch is undefined and could be the UNIX epoch, time since boot, time since launch, etc. | |||||
*/ | */ | ||||
long getNanoseconds(); | |||||
int64_t getNanoseconds(); | |||||
/** Opens a URL, also happens to work with PDFs and folders. | /** Opens a URL, also happens to work with PDFs and folders. | ||||
Shell injection is possible, so make sure the URL is trusted or hard coded. | Shell injection is possible, so make sure the URL is trusted or hard coded. | ||||
May block, so open in a new thread. | May block, so open in a new thread. | ||||
@@ -51,8 +51,8 @@ struct MIDI_CC : Module { | |||||
// Process MIDI messages only if they arrived `stepFrames` frames ago. | // Process MIDI messages only if they arrived `stepFrames` frames ago. | ||||
while (!midiInput.queue.empty()) { | while (!midiInput.queue.empty()) { | ||||
midi::Message& msg = midiInput.queue.front(); | midi::Message& msg = midiInput.queue.front(); | ||||
long msgTime = msg.timestamp + long(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
long frameTime = APP->engine->getStepTime() + long((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
int64_t msgTime = msg.timestamp + int64_t(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
int64_t frameTime = APP->engine->getStepTime() + int64_t((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
if (msgTime > frameTime) | if (msgTime > frameTime) | ||||
break; | break; | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -122,8 +122,8 @@ struct MIDI_CV : Module { | |||||
// Process MIDI messages only if they arrived `stepFrames` frames ago. | // Process MIDI messages only if they arrived `stepFrames` frames ago. | ||||
while (!midiInput.queue.empty()) { | while (!midiInput.queue.empty()) { | ||||
midi::Message& msg = midiInput.queue.front(); | midi::Message& msg = midiInput.queue.front(); | ||||
long msgTime = msg.timestamp + long(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
long frameTime = APP->engine->getStepTime() + long((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
int64_t msgTime = msg.timestamp + int64_t(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
int64_t frameTime = APP->engine->getStepTime() + int64_t((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
if (msgTime > frameTime) | if (msgTime > frameTime) | ||||
break; | break; | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -58,8 +58,8 @@ struct MIDI_Gate : Module { | |||||
// Process MIDI messages only if they arrived `stepFrames` frames ago. | // Process MIDI messages only if they arrived `stepFrames` frames ago. | ||||
while (!midiInput.queue.empty()) { | while (!midiInput.queue.empty()) { | ||||
midi::Message& msg = midiInput.queue.front(); | midi::Message& msg = midiInput.queue.front(); | ||||
long msgTime = msg.timestamp + long(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
long frameTime = APP->engine->getStepTime() + long((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
int64_t msgTime = msg.timestamp + int64_t(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
int64_t frameTime = APP->engine->getStepTime() + int64_t((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
if (msgTime > frameTime) | if (msgTime > frameTime) | ||||
break; | break; | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -81,8 +81,8 @@ struct MIDI_Map : Module { | |||||
// Process MIDI messages only if they arrived `stepFrames` frames ago. | // Process MIDI messages only if they arrived `stepFrames` frames ago. | ||||
while (!midiInput.queue.empty()) { | while (!midiInput.queue.empty()) { | ||||
midi::Message& msg = midiInput.queue.front(); | midi::Message& msg = midiInput.queue.front(); | ||||
long msgTime = msg.timestamp + long(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
long frameTime = APP->engine->getStepTime() + long((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
int64_t msgTime = msg.timestamp + int64_t(APP->engine->getStepFrames() * APP->engine->getSampleTime() * 1e9); | |||||
int64_t frameTime = APP->engine->getStepTime() + int64_t((APP->engine->getFrame() - APP->engine->getStepFrame()) * APP->engine->getSampleTime() * 1e9); | |||||
if (msgTime > frameTime) | if (msgTime > frameTime) | ||||
break; | break; | ||||
processMessage(msg); | processMessage(msg); | ||||
@@ -151,9 +151,9 @@ struct Engine::Internal { | |||||
float sampleRate = 0.f; | float sampleRate = 0.f; | ||||
float sampleTime = 0.f; | float sampleTime = 0.f; | ||||
long frame = 0; | |||||
long stepFrame = 0; | |||||
long stepTime = 0; | |||||
int64_t frame = 0; | |||||
int64_t stepFrame = 0; | |||||
int64_t stepTime = 0; | |||||
int stepFrames = 0; | int stepFrames = 0; | ||||
Module* primaryModule = NULL; | Module* primaryModule = NULL; | ||||
@@ -224,7 +224,7 @@ static void Engine_stepModulesWorker(Engine* that, int threadId) { | |||||
Module* module = internal->modules[i]; | Module* module = internal->modules[i]; | ||||
// Start CPU timer | // Start CPU timer | ||||
long startTime; | |||||
int64_t startTime; | |||||
if (cpuMeter) { | if (cpuMeter) { | ||||
startTime = system::getNanoseconds(); | startTime = system::getNanoseconds(); | ||||
} | } | ||||
@@ -237,8 +237,8 @@ static void Engine_stepModulesWorker(Engine* that, int threadId) { | |||||
// Stop CPU timer | // Stop CPU timer | ||||
if (cpuMeter) { | if (cpuMeter) { | ||||
long endTime = system::getNanoseconds(); | |||||
float duration = (endTime - startTime) / 1e9; | |||||
int64_t endTime = system::getNanoseconds(); | |||||
float duration = (endTime - startTime) * 1e-9f; | |||||
// Smooth CPU time | // Smooth CPU time | ||||
const float cpuTau = 2.f /* seconds */; | const float cpuTau = 2.f /* seconds */; | ||||
@@ -521,19 +521,19 @@ void Engine::yieldWorkers() { | |||||
} | } | ||||
long Engine::getFrame() { | |||||
int64_t Engine::getFrame() { | |||||
// No lock, for performance | // No lock, for performance | ||||
return internal->frame; | return internal->frame; | ||||
} | } | ||||
long Engine::getStepFrame() { | |||||
int64_t Engine::getStepFrame() { | |||||
// No lock, for performance | // No lock, for performance | ||||
return internal->stepFrame; | return internal->stepFrame; | ||||
} | } | ||||
long Engine::getStepTime() { | |||||
int64_t Engine::getStepTime() { | |||||
// No lock, for performance | // No lock, for performance | ||||
return internal->stepTime; | return internal->stepTime; | ||||
} | } | ||||
@@ -10,7 +10,7 @@ namespace logger { | |||||
static FILE* outputFile = NULL; | static FILE* outputFile = NULL; | ||||
static long startTime = 0; | |||||
static int64_t startTime = 0; | |||||
static std::mutex logMutex; | static std::mutex logMutex; | ||||
@@ -50,7 +50,7 @@ static const int levelColors[] = { | |||||
static void logVa(Level level, const char* filename, int line, const char* format, va_list args) { | static void logVa(Level level, const char* filename, int line, const char* format, va_list args) { | ||||
std::lock_guard<std::mutex> lock(logMutex); | std::lock_guard<std::mutex> lock(logMutex); | ||||
long nowTime = system::getNanoseconds(); | |||||
int64_t nowTime = system::getNanoseconds(); | |||||
double duration = (nowTime - startTime) / 1e9; | double duration = (nowTime - startTime) / 1e9; | ||||
if (outputFile == stderr) | if (outputFile == stderr) | ||||
fprintf(outputFile, "\x1B[%dm", levelColors[level]); | fprintf(outputFile, "\x1B[%dm", levelColors[level]); | ||||
@@ -215,13 +215,24 @@ std::string getStackTrace() { | |||||
} | } | ||||
long getNanoseconds() { | |||||
int64_t getNanoseconds() { | |||||
#if defined ARCH_WIN | |||||
LARGE_INTEGER counter; | |||||
QueryPerformanceCounter(&counter); | |||||
LARGE_INTEGER frequency; | |||||
QueryPerformanceFrequency(&frequency); | |||||
// TODO Check if this is always an integer factor on all CPUs | |||||
int64_t nsPerTick = 1000000000LL / frequency.QuadPart; | |||||
int64_t time = counter.QuadPart * nsPerTick; | |||||
return time; | |||||
#else | |||||
using clock = std::chrono::high_resolution_clock; | using clock = std::chrono::high_resolution_clock; | ||||
using time_point = std::chrono::time_point<clock>; | using time_point = std::chrono::time_point<clock>; | ||||
time_point now = clock::now(); | time_point now = clock::now(); | ||||
using duration = std::chrono::duration<long, std::nano>; | |||||
using duration = std::chrono::duration<int64_t, std::nano>; | |||||
duration d = now.time_since_epoch(); | duration d = now.time_since_epoch(); | ||||
return d.count(); | return d.count(); | ||||
#endif | |||||
} | } | ||||