Example #1
0
FFT_BRUSH getKeyBrush(FFT_RESULT* result, int keyIndex)
{
    float r = 0;
    float g = 0;
    float b = 0;

    if (result->wavFile == NULL)
    {
        return createBrush((int)r, (int)g, (int)b);
    }

    float f = pFreqTable[keyIndex];
    int sampleRate = result->wavFile->header.SampleRate;
    int samples = result->samples;
    assert(sampleRate != 0);
    float fPerBin = sampleRate / (float)samples;
    int binIndex = (int) round(f / fPerBin);
    int maxBinIndex = (samples / 2) + 1;

    if (binIndex > maxBinIndex || binIndex == 0)
    {
        return createBrush((int)r, (int)g, (int)b);
    }

    kiss_fft_scalar value = sqrt(pow(result->bins[binIndex].r, 2) + pow(result->bins[binIndex].i, 2));
    magnitudes[keyIndex] = fmax(value, magnitudes[keyIndex]);
    float h = 0;
    float s = 1;
    float v = 1;
    h = magnitudes[keyIndex] / ((kiss_fft_scalar)samples / 2) * 360;
    magnitudes[keyIndex] *= 0.90;
    HSVtoRGB( &r, &g, &b, h, s, v );

    return createBrush((int)floor(r * 254), (int)floor(g * 254), (int)floor(b * 254));
}
Example #2
0
void NewBrushCommand::onExecute(Context* context)
{
  ASSERT(current_editor);
  if (!current_editor)
    return;

  // If there is no visible mask, the brush must be selected from the
  // current editor.
  if (!context->activeDocument()->isMaskVisible()) {
    EditorStatePtr state = current_editor->getState();
    if (dynamic_cast<SelectBoxState*>(state.get())) {
      // If already are in "SelectBoxState" state, in this way we
      // avoid creating a stack of several "SelectBoxState" states.
      return;
    }

    current_editor->setState(
      EditorStatePtr(
        new SelectBoxState(
          this, current_editor->sprite()->bounds(),
          SelectBoxState::DARKOUTSIDE |
          SelectBoxState::QUICKBOX)));
  }
  // Create a brush from the active selection
  else {
    createBrush(context->activeDocument()->mask());
    selectPencilTool();

    // Deselect mask
    Command* cmd =
      CommandsModule::instance()->getCommandByName(CommandId::DeselectMask);
    UIContext::instance()->executeCommand(cmd);
  }
}
Example #3
0
void NewBrushCommand::onQuickboxEnd(const gfx::Rect& rect, ui::MouseButtons buttons)
{
  Mask mask;
  mask.replace(rect);
  createBrush(&mask);
  selectPencilTool();

  // If the right-button was used, we clear the selected area.
  if (buttons & ui::kButtonRight) {
    try {
      ContextWriter writer(UIContext::instance(), 250);
      Transaction transaction(writer.context(), "Clear");
      transaction.execute(new cmd::ClearRect(writer.cel(), rect));
      transaction.commit();
    }
    catch (const std::exception& ex) {
      Console::showException(ex);
    }
  }

  // Update the context bar
  // TODO find a way to avoid all these singletons. Maybe a simple
  // signal in the context like "brush has changed" could be enough.
  App::instance()->getMainWindow()->getContextBar()
    ->updateForCurrentTool();

  current_editor->backToPreviousState();
}
Example #4
0
//--------------------------------------------------------------
// create a brush
const mgBrush* mgGenSurface::createBrush(
  double r, 
  double g, 
  double b,
  double a)
{
  return createBrush(mgColor(r, g, b, a));
}
void KisCustomBrushWidget::slotUpdateCurrentBrush(int)
{
    if (brushStyle->currentIndex() == 0) {
        comboBox2->setEnabled(false);
    }
    else {
        comboBox2->setEnabled(true);
    }
    if (m_image) {
        createBrush();
        if (m_brush){
            preview->setPixmap(QPixmap::fromImage( m_brush->image() ));
        }
    }
    emit sigBrushChanged();
}
Example #6
0
//--------------------------------------------------------------
// create a brush
const mgBrush* mgGenSurface::createBrush(
  const char* colorSpec)
{
  return createBrush(mgColor(colorSpec));
}
Example #7
0
 void MapReader::onEndBrush(const size_t startLine, const size_t lineCount, const ExtraAttributes& extraAttributes) {
     createBrush(startLine, lineCount, extraAttributes);
 }
Example #8
0
//--------------------------------------------------------------
// create a brush
const mgBrush* mgXPSurface::createBrush(
  const char* colorSpec)
{
  mgColor color(colorSpec);
  return createBrush(color.m_r, color.m_g, color.m_b);
}
Example #9
0
//--------------------------------------------------------------
// create a brush
const mgBrush* mgXPSurface::createBrush(
  const mgColor& color)
{
  return createBrush(color.m_r, color.m_g, color.m_b);
}