void Joystick::calculateDrawingSpot() { // Determine the current drawing location draw_x = roundDoubleToInt (floor (current_x * x_ratio)); draw_y = roundDoubleToInt (floor (current_y * y_ratio)); // If at max value, don't go over edge if (current_x == x_min) draw_x++; if (current_y == y_min) draw_y++; if (current_x == (x_max - x_min)) draw_x--; if (current_y == (y_max - y_min)) draw_y--; }
const String Joystick::getTextFromValue (double v) { if (numDecimalPlaces > 0) return String (v, numDecimalPlaces); else return String (roundDoubleToInt (v)); }
void updateParameters() { if (auto* cabinetTypeParameter = dynamic_cast<ChoiceParameter*> (parameters[0])) { if (cabinetTypeParameter->getCurrentSelectedID() == 1) { bypass = true; } else { bypass = false; auto maxSize = static_cast<size_t> (roundDoubleToInt (8192.0 * sampleRate / 44100.0)); if (cabinetTypeParameter->getCurrentSelectedID() == 2) convolution.loadImpulseResponse (BinaryData::guitar_amp_wav, BinaryData::guitar_amp_wavSize, false, true, maxSize); else convolution.loadImpulseResponse (BinaryData::cassette_recorder_wav, BinaryData::cassette_recorder_wavSize, false, true, maxSize); } } }
//============================================================================== // quick-and-dirty function to format a timecode string static const String timeToTimecodeString (const double seconds) { const double absSecs = fabs (seconds); const tchar* const sign = (seconds < 0) ? T("-") : T(""); const int hours = (int) (absSecs / (60.0 * 60.0)); const int mins = ((int) (absSecs / 60.0)) % 60; const int secs = ((int) absSecs) % 60; return String::formatted (T("%s%02d:%02d:%02d:%03d"), sign, hours, mins, secs, roundDoubleToInt (absSecs * 1000) % 1000); }
//============================================================================== void Joystick::paint (Graphics& g) { // Draw main section of box ------------------------ g.setColour (backgroundColour); g.fillAll (); // Determine the location of the snapback square --- int snap_x = roundDoubleToInt (floor (x_snap * x_ratio)); int snap_y = roundDoubleToInt (floor (y_snap * y_ratio)); // if at max value, don't go over edge if (x_snap == x_min) snap_x++; if (y_snap == x_min) snap_y++; if (x_snap == (x_max - x_min)) snap_x--; if (y_snap == (x_max - x_min)) snap_y--; // Draw the snapback square ------------------------ g.setColour (Colours::lightyellow); // g.fillEllipse(snap_x-2,snap_y-2,5,5); g.drawEllipse (snap_x - 4, snap_y - 4, 9, 9, 1.0); // Draw the main dot ------------------------------- if (holdOnMouseRelease) g.setColour (Colours::lightblue); else g.setColour (Colours::orange); g.fillEllipse (draw_x - 2, draw_y - 2, 5, 5); g.drawEllipse (draw_x - 4, draw_y - 4, 9, 9, 1.0); // Draw inset bevel -------------------------------- LookAndFeel::drawBevel (g, 0, 0, getWidth(), getHeight(), 2, insetDarkColour, insetLightColour, true); }
WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_) : device (device_), sampleRate (0), numChannels (0), actualNumChannels (0), defaultSampleRate (0), minBufferSize (0), defaultBufferSize (0), latencySamples (0) { clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI")); ComSmartPtr <IAudioClient> tempClient (createClient()); if (tempClient == 0) return; REFERENCE_TIME defaultPeriod, minPeriod; if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod))) return; WAVEFORMATEX* mixFormat = 0; if (! OK (tempClient->GetMixFormat (&mixFormat))) return; WAVEFORMATEXTENSIBLE format; wasapi_copyWavFormat (format, mixFormat); CoTaskMemFree (mixFormat); actualNumChannels = numChannels = format.Format.nChannels; defaultSampleRate = format.Format.nSamplesPerSec; minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate); defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate); FloatElementComparator<double> comparator; rates.addSorted (comparator, defaultSampleRate); static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 }; for (int i = 0; i < numElementsInArray (ratesToTest); ++i) { if (ratesToTest[i] == defaultSampleRate) continue; format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]); if (SUCCEEDED (tempClient->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, 0))) if (! rates.contains (ratesToTest[i])) rates.addSorted (comparator, ratesToTest[i]); } }
void PizLookAndFeel::drawRotarySlider (Graphics& g, int x, int y, int width, int height, float sliderPos, const float rotaryStartAngle, const float rotaryEndAngle, Slider& slider) { g.fillAll (slider.findColour (Slider::backgroundColourId)); const float radius = jmin (width / 2, height / 2) - 2.0f; const float centreX = x + width * 0.5f; const float centreY = y + height * 0.5f; //const float rx = centreX - radius; //const float ry = centreY - radius; const float rw = radius * 2.0f; const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle); const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled(); if (slider.isEnabled()) g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId).withMultipliedAlpha (isMouseOver ? 1.0f : 0.7f)); else g.setColour (Colour (0x80808080)); Path p; p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f); PathStrokeType (rw * 0.1f).createStrokedPath (p, p); g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY)); Path m; m.addLineSegment (Line<float>(0.0f, 0.0f, 0.0f, -radius), rw * 0.2f); g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withMultipliedAlpha (isMouseOver ? 1.0f : 0.8f)); g.fillPath (m, AffineTransform::rotation (angle).translated (centreX, centreY)); g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f)); Font font("small fonts",slider.getHeight()*0.4f,Font::bold); g.setFont(font); g.drawFittedText(String(roundDoubleToInt(slider.getValue())),0,0,width,height,Justification::centred,1); }
/** Copy the states of another engine. */ void copyStateFromOtherEngine (const ConvolutionEngine& other) { if (FFTSize != other.FFTSize) { FFTobject = new FFT (roundDoubleToInt (log2 (other.FFTSize))); FFTSize = other.FFTSize; } currentSegment = other.currentSegment; numInputSegments = other.numInputSegments; numSegments = other.numSegments; blockSize = other.blockSize; inputDataPos = other.inputDataPos; bufferInput = other.bufferInput; bufferTempOutput = other.bufferTempOutput; bufferOutput = other.bufferOutput; buffersInputSegments = other.buffersInputSegments; buffersImpulseSegments = other.buffersImpulseSegments; bufferOverlap = other.bufferOverlap; isReady = true; }
static long floatToLong (const float n) throw() { return roundDoubleToInt (jlimit (-(double) 0x80000000, (double) 0x7fffffff, n * (double) 0xffffffff - (double) 0x80000000)); }
int refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) noexcept { return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001); }
void Upsampler::setOutputBufferSize(double seconds) { maxOutputSampleCount = roundDoubleToInt(seconds * outputSampleRate); outputBuffer.allocate(maxOutputSampleCount, true); }
Result Upsampler::upsample(AudioBuffer<float> const &inputBuffer, int const inputChannel, AudioBuffer<float> &outputBuffer_, int const outputChannel, int &outputSampleCount_) { int outputSamplesNeeded = roundDoubleToInt( (outputSampleRate * inputBuffer.getNumSamples())/ inputSampleRate); if (outputBuffer_.getNumSamples() < outputSamplesNeeded) return Result::fail("Output buffer too small"); //DBG("upsample inputSampleCount:" << inputSampleCount); if (nullptr == resampler) return Result::fail("No resampler object"); // // Clear the resample and pump some initial zeros into it // resampler->clear(); #if 0 int preloadSamples = resampler->getInLenBeforeOutStart(MAX_RESAMPLER_INPUT_SAMPLES); inputBlockBuffer.clear(MAX_RESAMPLER_INPUT_SAMPLES); while (preloadSamples > 0) { int count = jmin((int)MAX_RESAMPLER_INPUT_SAMPLES, preloadSamples); double* outputBlock = nullptr; resampler->process(inputBlockBuffer, count, outputBlock); preloadSamples -= count; } #endif // // Flush the output buffer // outputBuffer_.clear(); // // Do the actual upsample // outputSampleCount_ = 0; int inputSampleCount = inputBuffer.getNumSamples(); const float * source = inputBuffer.getReadPointer(inputChannel); while (inputSampleCount > 0) { // // Convert float to double // int inputConvertCount = jmin(inputSampleCount, (int)MAX_RESAMPLER_INPUT_SAMPLES); for (int i = 0; i < inputConvertCount; ++i) { inputBlockBuffer[i] = *source; source++; } inputSampleCount -= inputConvertCount; // // Run the SRC // double* outputBlock = nullptr; int outputBlockSampleCount = resampler->process(inputBlockBuffer, inputConvertCount, outputBlock); int outputSpaceRemaining = outputBuffer_.getNumSamples() - outputSampleCount_; int outputCopyCount = jmin( outputSpaceRemaining, outputBlockSampleCount); float *destination = outputBuffer_.getWritePointer(outputChannel, outputSampleCount_); for (int i = 0; i < outputCopyCount; ++i) { *destination = (float)outputBlock[i]; destination++; } outputSampleCount_ += outputCopyCount; } // // Keep filling the output buffer // inputBlockBuffer.clear(MAX_RESAMPLER_INPUT_SAMPLES); while (outputSampleCount_ < outputBuffer_.getNumSamples()) { // // Run the SRC // double* outputBlock = nullptr; int outputBlockSampleCount = resampler->process(inputBlockBuffer, MAX_RESAMPLER_INPUT_SAMPLES, outputBlock); int outputSpaceRemaining = outputBuffer_.getNumSamples() - outputSampleCount_; int outputCopyCount = jmin( outputSpaceRemaining, outputBlockSampleCount); float *destination = outputBuffer_.getWritePointer(outputChannel, outputSampleCount_); for (int i = 0; i < outputCopyCount; ++i) { *destination = (float)outputBlock[i]; destination++; } outputSampleCount_ += outputCopyCount; } //DBG(" outputSampleCount:" << outputSampleCount); return Result::ok(); }
bool SmugMug::getNumberOfViews(int month, int year, OwnedArray<Views>& albums, OwnedArray<Views>& images) { StringPairArray params; params.set(("Month"), String(month)); params.set(("Year"), String(year)); XmlElement* n = smugMugRequest(("smugmug.users.getTransferStats"), params); if (n) { XmlElement* albs = n->getChildByName(("Albums")); if (albs) { XmlElement* alb = albs->getChildByName(("Album")); while (alb) { Views* v = new Views(); v->id = alb->getIntAttribute(("id")); v->views = alb->getIntAttribute(("Tiny")) + alb->getIntAttribute(("Small")) + alb->getIntAttribute(("Medium")) + alb->getIntAttribute(("Large")) + roundDoubleToInt(alb->getDoubleAttribute(("Original"))); albums.add(v); XmlElement* img = n->getChildByName(("Image")); while (img) { Views* v = new Views(); v->id = img->getIntAttribute(("id")); v->views = img->getIntAttribute(("Tiny")) + img->getIntAttribute(("Small")) + img->getIntAttribute(("Medium")) + img->getIntAttribute(("Large")) + roundDoubleToInt(img->getDoubleAttribute(("Original"))); img = img->getNextElementWithTagName(("Image")); } alb = alb->getNextElementWithTagName(("Album")); } } delete n; return true; } return false; }
void TaskContextViewComponent::paint (Graphics& g) { TaskContext* handler = getTaskContext (); if (handler != nullptr) { String name = handler->getTask().getName(); String msg = handler->getTask().getStatusMessage(); // if (rowIsSelected) // { // g.setColour (Colours::darkgrey.withAlpha(0.3f)); // g.fillAll (); // } g.setColour (Colours::black); Rectangle<int> area (0,0,getWidth(),getHeight()); area = area.reduced (4); int halfHeight = getHeight()/2; g.drawFittedText(handler->getTask().getName(), getLocalBounds().withTrimmedBottom(halfHeight).reduced(4), Justification::centredLeft, 1); //g.drawFittedText(handler->getStateDescription(), getLocalBounds().withTrimmedTop(halfHeight).reduced(4), Justification::centredLeft, 1); switch (handler->getState()) { case TaskContext::taskPending: { g.setColour (Colours::blue.withAlpha(0.2f)); g.fillRect (area.reduced(2)); } break; case TaskContext::taskRunning: { double prog = handler->getTask().getProgress();//getOverallProgress(); g.setColour (Colours::hotpink.withAlpha(0.5f)); g.fillRect (area.reduced(2).withTrimmedRight (roundDoubleToInt (area.getWidth() * (1 - prog)))); } break; case TaskContext::taskCompleted: { g.setColour (Colours::green.withAlpha(0.5f)); g.fillRect (area.reduced(2)); } break; case TaskContext::taskAborted: { g.setColour (Colours::red.withAlpha(0.5f)); g.fillRect (area.reduced(2)); } break; case TaskContext::taskStarting: { g.setColour (Colours::brown.withAlpha(0.5f)); g.fillRect (area.reduced(2)); } break; default:; break; } } }
bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry) { WAVEFORMATEXTENSIBLE format; zerostruct (format); if (numChannels <= 2 && bytesPerSampleToTry <= 2) { format.Format.wFormatTag = WAVE_FORMAT_PCM; } else { format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX); } format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate); format.Format.nChannels = (WORD) numChannels; format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry); format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry); format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry); format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM; format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample; switch (numChannels) { case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break; case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break; case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break; case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break; case 8: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT | SPEAKER_FRONT_LEFT_OF_CENTER | SPEAKER_FRONT_RIGHT_OF_CENTER; break; default: break; } WAVEFORMATEXTENSIBLE* nearestFormat = 0; HRESULT hr = client->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, (WAVEFORMATEX**) &nearestFormat); logFailure (hr); if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec) { wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat); hr = S_OK; } CoTaskMemFree (nearestFormat); GUID session; if (hr == S_OK && OK (client->Initialize (AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, 0, 0, (WAVEFORMATEX*) &format, &session))) { actualNumChannels = format.Format.nChannels; const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT; bytesPerSample = format.Format.wBitsPerSample / 8; dataFormat = isFloat ? AudioDataConverters::float32LE : (bytesPerSample == 4 ? AudioDataConverters::int32LE : ((bytesPerSample == 3 ? AudioDataConverters::int24LE : AudioDataConverters::int16LE))); return true; } return false; }
static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw() { return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001); }