Search in sources :

Example 21 with ColorEx

use of de.mossgrabers.framework.controller.color.ColorEx in project DrivenByMoss by git-moss.

the class ListComponent method draw.

/**
 * {@inheritDoc}
 */
@Override
public void draw(final IGraphicsInfo info) {
    final IGraphicsContext gc = info.getContext();
    final IGraphicsDimensions dimensions = info.getDimensions();
    final IGraphicsConfiguration configuration = info.getConfiguration();
    final double left = info.getBounds().left();
    final double width = info.getBounds().width();
    final double height = info.getBounds().height();
    final double separatorSize = dimensions.getSeparatorSize();
    final double inset = dimensions.getInset();
    final int size = this.items.size();
    final double itemLeft = left + separatorSize;
    final double itemWidth = width - separatorSize;
    final double itemHeight = height / size;
    final ColorEx textColor = configuration.getColorText();
    final ColorEx borderColor = configuration.getColorBorder();
    for (int i = 0; i < size; i++) {
        final Pair<String, Boolean> item = this.items.get(i);
        final boolean isSelected = item.getValue().booleanValue();
        final double itemTop = i * itemHeight;
        gc.fillRectangle(itemLeft, itemTop + separatorSize, itemWidth, itemHeight - 2 * separatorSize, isSelected ? textColor : borderColor);
        gc.drawTextInBounds(item.getKey(), itemLeft + inset, itemTop, itemWidth - 2 * inset, itemHeight, Align.LEFT, isSelected ? borderColor : textColor, itemHeight * 0.6);
    }
}
Also used : IGraphicsContext(de.mossgrabers.framework.graphics.IGraphicsContext) IGraphicsConfiguration(de.mossgrabers.framework.graphics.IGraphicsConfiguration) ColorEx(de.mossgrabers.framework.controller.color.ColorEx) IGraphicsDimensions(de.mossgrabers.framework.graphics.IGraphicsDimensions)

Example 22 with ColorEx

use of de.mossgrabers.framework.controller.color.ColorEx in project DrivenByMoss by git-moss.

the class MidiClipComponent method draw.

/**
 * {@inheritDoc}
 */
@Override
public void draw(final IGraphicsInfo info) {
    final IGraphicsConfiguration configuration = info.getConfiguration();
    final ColorEx gridBackground = configuration.getColorBackgroundLighter();
    final ColorEx measureTextColor = ColorEx.WHITE;
    final ColorEx dividersColor = configuration.getColorBackgroundDarker();
    final ColorEx noteColor = this.clip.getColor();
    final ColorEx noteMutedColor = ColorEx.DARK_GRAY;
    final ColorEx noteGridLoopColor = configuration.getColorBackground();
    final ColorEx noteBorderColor = ColorEx.BLACK;
    final IGraphicsContext gc = info.getContext();
    final double left = info.getBounds().left();
    final double width = info.getBounds().width();
    final double height = info.getBounds().height();
    final int top = 14;
    final double noteAreaHeight = height - top;
    // Draw the background
    gc.fillRectangle(left, top, width, noteAreaHeight, gridBackground);
    // Draw the loop, if any and ...
    final int numSteps = this.clip.getNumSteps();
    final double stepLength = this.clip.getStepLength();
    final double pageLength = numSteps * stepLength;
    final int editPage = this.clip.getEditPage();
    final double startPos = editPage * pageLength;
    final double endPos = (editPage + 1) * pageLength;
    final int len = top - 1;
    if (this.clip.isLoopEnabled()) {
        final double loopStart = this.clip.getLoopStart();
        final double loopLength = this.clip.getLoopLength();
        // ... the loop is visible in the current page
        if (loopStart < endPos && loopStart + loopLength > startPos) {
            final double start = Math.max(0, loopStart - startPos);
            final double end = Math.min(endPos, loopStart + loopLength) - startPos;
            final double x = width * start / pageLength;
            final double w = width * end / pageLength - x;
            // The header loop
            gc.fillRectangle(x + 1, 0, w, len, noteColor);
            // Background in note area
            gc.fillRectangle(x + 1, top, w, noteAreaHeight, noteGridLoopColor);
        }
    }
    // Draw play start in header
    final double playStart = this.clip.getPlayStart();
    if (playStart >= startPos && playStart <= endPos) {
        final double start = playStart - startPos;
        final double x = width * start / pageLength;
        gc.fillTriangle(x + 1, 0, x + 1 + len, len / 2.0, x + 1, len, noteColor);
        gc.strokeTriangle(x + 1, 0, x + 1 + len, len / 2.0, x + 1, len, ColorEx.evenDarker(noteColor));
    }
    // Draw play end in header
    final double playEnd = this.clip.getPlayEnd();
    if (playEnd >= startPos && playEnd <= endPos) {
        final double end = playEnd - startPos;
        final double x = width * end / pageLength;
        gc.fillTriangle(x + 1, 0, x + 1, len, x + 1 - top, len / 2.0, noteColor);
        gc.strokeTriangle(x + 1, 0, x + 1, len, x + 1 - top, len / 2.0, ColorEx.evenDarker(noteColor));
    }
    // Draw dividers
    final double stepWidth = width / numSteps;
    for (int step = 0; step <= numSteps; step++) {
        final double x = left + step * stepWidth;
        gc.fillRectangle(x, top, 1, noteAreaHeight, dividersColor);
        // Draw measure texts
        if (step % 4 == 0) {
            final double time = startPos + step * stepLength;
            final String measureText = StringUtils.formatMeasures(this.quartersPerMeasure, time, 1, false);
            gc.drawTextInHeight(measureText, x, 0, top - 1.0, measureTextColor, top);
        }
    }
    // Draw the notes
    final int lowerRowWithData = this.clip.getLowerRowWithData();
    if (lowerRowWithData == -1)
        return;
    final int upperRowWithData = this.clip.getUpperRowWithData();
    // Display at least 4 rows
    final int range = Math.max(4, 1 + upperRowWithData - lowerRowWithData);
    final double stepHeight = noteAreaHeight / range;
    final double fontSize = gc.calculateFontSize("G#5", stepHeight, stepWidth, 12.0);
    for (int row = 0; row < range; row++) {
        gc.fillRectangle(left, top + (range - row - 1) * stepHeight, width, 1, dividersColor);
        for (int step = 0; step < numSteps; step++) {
            final int note = lowerRowWithData + row;
            // Get step, check for length
            for (int channel = 0; channel < 16; channel++) {
                final IStepInfo stepInfo = this.clip.getStep(channel, step, note);
                final StepState stepState = stepInfo.getState();
                if (stepState == StepState.OFF)
                    continue;
                double x = left + step * stepWidth - 1;
                double w = stepWidth + 2;
                final boolean isStart = stepState == StepState.START;
                if (isStart) {
                    x += 2;
                    w -= 2;
                }
                gc.strokeRectangle(x, top + (range - row - 1) * stepHeight + 2, w, stepHeight - 2, noteBorderColor);
                gc.fillRectangle(x + (isStart ? 0 : -2), top + (range - row - 1) * stepHeight + 2, w - 1 + (isStart ? 0 : 2), stepHeight - 3, stepInfo.isMuted() ? noteMutedColor : noteColor);
                if (isStart && fontSize > 0) {
                    final String text = channel + 1 + ": " + Scales.formatDrumNote(note);
                    final ColorEx textColor = ColorEx.calcContrastColor(noteColor);
                    gc.drawTextInBounds(text, x, top + (range - row - 1) * stepHeight + 2, w - 1, stepHeight - 3, Align.CENTER, textColor, fontSize);
                }
            }
        }
    }
    // Draw the play cursor
    final int playStep = this.clip.getCurrentStep();
    if (playStep >= 0)
        gc.fillRectangle(left + playStep * stepWidth - 1, 0, 3, height, measureTextColor);
}
Also used : IGraphicsContext(de.mossgrabers.framework.graphics.IGraphicsContext) StepState(de.mossgrabers.framework.daw.StepState) IGraphicsConfiguration(de.mossgrabers.framework.graphics.IGraphicsConfiguration) ColorEx(de.mossgrabers.framework.controller.color.ColorEx) IStepInfo(de.mossgrabers.framework.daw.IStepInfo)

Example 23 with ColorEx

use of de.mossgrabers.framework.controller.color.ColorEx in project DrivenByMoss by git-moss.

the class ParameterComponent method draw.

/**
 * {@inheritDoc}
 */
@Override
public void draw(final IGraphicsInfo info) {
    super.draw(info);
    final IGraphicsContext gc = info.getContext();
    final IGraphicsDimensions dimensions = info.getDimensions();
    final IGraphicsConfiguration configuration = info.getConfiguration();
    final double left = info.getBounds().left();
    final double width = info.getBounds().width();
    final double height = info.getBounds().height();
    final double separatorSize = dimensions.getSeparatorSize();
    final double menuHeight = dimensions.getMenuHeight();
    final double unit = dimensions.getUnit();
    final double controlsTop = dimensions.getControlsTop();
    final double inset = dimensions.getInset();
    final boolean isValueMissing = this.paramValue == -1;
    final boolean isModulated = this.modulatedParamValue != -1;
    final int trackRowHeight = (int) (1.6 * unit);
    final double trackRowTop = height - trackRowHeight - unit - separatorSize;
    // Component is off if the name is empty
    if (this.paramName == null || this.paramName.length() == 0)
        return;
    final double elementWidth = width - 2 * inset;
    final double elementHeight = (trackRowTop - controlsTop - inset) / 3;
    // Draw the background
    final ColorEx backgroundColor = configuration.getColorBackground();
    gc.fillRectangle(left, menuHeight + 1, width, trackRowTop - (isValueMissing ? controlsTop + elementHeight : menuHeight + 1), this.isTouched ? configuration.getColorBackgroundLighter() : backgroundColor);
    // Draw the name and value texts
    final ColorEx textColor = configuration.getColorText();
    final double fontSize = elementHeight * 2 / 3;
    gc.drawTextInBounds(this.paramName, left + inset - 1, controlsTop - inset, elementWidth, elementHeight, Align.CENTER, textColor, fontSize);
    gc.drawTextInBounds(this.paramValueText, left + inset - 1, controlsTop - inset + elementHeight, elementWidth, elementHeight, Align.CENTER, textColor, fontSize);
    // Value slider
    if (isValueMissing)
        return;
    final double elementInnerWidth = elementWidth - 2;
    final double maxValue = dimensions.getParameterUpperBound();
    final double value = isModulated ? this.modulatedParamValue : this.paramValue;
    final double valueSliderWidth = value >= maxValue - 1 ? elementInnerWidth : elementInnerWidth * value / maxValue;
    final double innerTop = controlsTop + 2 * elementHeight + 1;
    final ColorEx borderColor = configuration.getColorBorder();
    gc.fillRectangle(left + inset - 1, controlsTop + 2 * elementHeight, elementWidth, elementHeight, borderColor);
    gc.fillRectangle(left + inset, innerTop, valueSliderWidth, elementHeight - 2, configuration.getColorFader());
    final double w = this.isTouched ? 3 : 1;
    final double valueWidth = this.paramValue >= maxValue - 1 ? elementInnerWidth : elementInnerWidth * this.paramValue / maxValue;
    gc.fillRectangle(left + inset + Math.max(0, valueWidth - w), innerTop, w, elementHeight - 2, configuration.getColorEdit());
}
Also used : IGraphicsContext(de.mossgrabers.framework.graphics.IGraphicsContext) IGraphicsConfiguration(de.mossgrabers.framework.graphics.IGraphicsConfiguration) ColorEx(de.mossgrabers.framework.controller.color.ColorEx) IGraphicsDimensions(de.mossgrabers.framework.graphics.IGraphicsDimensions)

Example 24 with ColorEx

use of de.mossgrabers.framework.controller.color.ColorEx in project DrivenByMoss by git-moss.

the class EncodedColorLightState method getVisualState.

/**
 * {@inheritDoc}}
 */
@Override
public HardwareLightVisualState getVisualState() {
    if (this.encodedColorState == -1)
        return HardwareLightVisualState.createForColor(Color.blackColor(), Color.whiteColor());
    final int colorIndex = this.encodedColorState & 0xFF;
    final int blinkColorIndex = this.encodedColorState >> 8 & 0xFF;
    final boolean blinkFast = (this.encodedColorState >> 16 & 1) > 0;
    final ColorEx colorEx = this.stateToColorFunction.apply(colorIndex);
    final Color color = Color.fromRGB(colorEx.getRed(), colorEx.getGreen(), colorEx.getBlue());
    final ColorEx contrastColorEx = ColorEx.calcContrastColor(colorEx);
    final Color contrastColor = Color.fromRGB(contrastColorEx.getRed(), contrastColorEx.getGreen(), contrastColorEx.getBlue());
    if (blinkColorIndex <= 0 || blinkColorIndex >= 128)
        return HardwareLightVisualState.createForColor(color, contrastColor);
    final ColorEx blinkColorEx = this.stateToColorFunction.apply(blinkColorIndex);
    final Color blinkColor = Color.fromRGB(blinkColorEx.getRed(), blinkColorEx.getGreen(), blinkColorEx.getBlue());
    final ColorEx contrastBlinkColorEx = ColorEx.calcContrastColor(blinkColorEx);
    final Color contrastBlinkColor = Color.fromRGB(contrastBlinkColorEx.getRed(), contrastBlinkColorEx.getGreen(), contrastBlinkColorEx.getBlue());
    final double blinkTimeInSec = blinkFast ? 0.5 : 1;
    return HardwareLightVisualState.createBlinking(blinkColor, color, contrastBlinkColor, contrastColor, blinkTimeInSec, blinkTimeInSec);
}
Also used : ColorEx(de.mossgrabers.framework.controller.color.ColorEx) Color(com.bitwig.extension.api.Color)

Example 25 with ColorEx

use of de.mossgrabers.framework.controller.color.ColorEx in project DrivenByMoss by git-moss.

the class HwSurfaceFactoryImpl method createLight.

/**
 * {@inheritDoc}
 */
@Override
public IHwLight createLight(final int surfaceID, final OutputID outputID, final IntSupplier supplier, final IntConsumer sendValueConsumer, final IntFunction<ColorEx> stateToColorFunction, final IHwButton button) {
    this.lightCounter++;
    final String id = createID(surfaceID, outputID == null ? "LIGHT" + this.lightCounter : outputID.name());
    final MultiStateHardwareLight hardwareLight = this.hardwareSurface.createMultiStateHardwareLight(id);
    final Supplier<InternalHardwareLightState> valueSupplier = () -> new EncodedColorLightState(supplier.getAsInt(), stateToColorFunction);
    final Consumer<InternalHardwareLightState> hardwareUpdater = state -> {
        final HardwareLightVisualState visualState = state == null ? null : state.getVisualState();
        final int encodedColorState = visualState == null ? 0 : supplier.getAsInt();
        sendValueConsumer.accept(encodedColorState);
    };
    final HwLightImpl lightImpl = new HwLightImpl(this.host, hardwareLight, valueSupplier, hardwareUpdater);
    if (button != null)
        button.addLight(lightImpl);
    return lightImpl;
}
Also used : IHwTextDisplay(de.mossgrabers.framework.controller.hardware.IHwTextDisplay) IHwButton(de.mossgrabers.framework.controller.hardware.IHwButton) HostImpl(de.mossgrabers.bitwig.framework.daw.HostImpl) Color(com.bitwig.extension.api.Color) IntConsumer(java.util.function.IntConsumer) IHwSurfaceFactory(de.mossgrabers.framework.controller.hardware.IHwSurfaceFactory) HardwareLightVisualState(com.bitwig.extension.controller.api.HardwareLightVisualState) OutputID(de.mossgrabers.framework.controller.OutputID) Supplier(java.util.function.Supplier) IHwPianoKeyboard(de.mossgrabers.framework.controller.hardware.IHwPianoKeyboard) RelativeEncoding(de.mossgrabers.framework.controller.valuechanger.RelativeEncoding) ButtonID(de.mossgrabers.framework.controller.ButtonID) ColorEx(de.mossgrabers.framework.controller.color.ColorEx) IntSupplier(java.util.function.IntSupplier) IntFunction(java.util.function.IntFunction) BitmapImpl(de.mossgrabers.bitwig.framework.graphics.BitmapImpl) IHwLight(de.mossgrabers.framework.controller.hardware.IHwLight) OperatingSystem(de.mossgrabers.framework.utils.OperatingSystem) MultiStateHardwareLight(com.bitwig.extension.controller.api.MultiStateHardwareLight) HardwareButton(com.bitwig.extension.controller.api.HardwareButton) ContinuousID(de.mossgrabers.framework.controller.ContinuousID) IHwFader(de.mossgrabers.framework.controller.hardware.IHwFader) Consumer(java.util.function.Consumer) IBitmap(de.mossgrabers.framework.graphics.IBitmap) IHwAbsoluteKnob(de.mossgrabers.framework.controller.hardware.IHwAbsoluteKnob) IHwGraphicsDisplay(de.mossgrabers.framework.controller.hardware.IHwGraphicsDisplay) IHwRelativeKnob(de.mossgrabers.framework.controller.hardware.IHwRelativeKnob) HardwareSurface(com.bitwig.extension.controller.api.HardwareSurface) InternalHardwareLightState(com.bitwig.extension.controller.api.InternalHardwareLightState) MultiStateHardwareLight(com.bitwig.extension.controller.api.MultiStateHardwareLight) InternalHardwareLightState(com.bitwig.extension.controller.api.InternalHardwareLightState) HardwareLightVisualState(com.bitwig.extension.controller.api.HardwareLightVisualState)

Aggregations

ColorEx (de.mossgrabers.framework.controller.color.ColorEx)35 IGraphicsConfiguration (de.mossgrabers.framework.graphics.IGraphicsConfiguration)12 IGraphicsContext (de.mossgrabers.framework.graphics.IGraphicsContext)12 IGraphicsDimensions (de.mossgrabers.framework.graphics.IGraphicsDimensions)9 IStepInfo (de.mossgrabers.framework.daw.IStepInfo)6 Color (com.bitwig.extension.api.Color)5 INoteClip (de.mossgrabers.framework.daw.INoteClip)5 GridStep (de.mossgrabers.framework.daw.data.GridStep)5 ITrack (de.mossgrabers.framework.daw.data.ITrack)5 IPadGrid (de.mossgrabers.framework.controller.grid.IPadGrid)4 IValueChanger (de.mossgrabers.framework.controller.valuechanger.IValueChanger)4 ITrackBank (de.mossgrabers.framework.daw.data.bank.ITrackBank)4 ButtonID (de.mossgrabers.framework.controller.ButtonID)3 IDrumDevice (de.mossgrabers.framework.daw.data.IDrumDevice)3 HardwareButton (com.bitwig.extension.controller.api.HardwareButton)2 HardwareLightVisualState (com.bitwig.extension.controller.api.HardwareLightVisualState)2 HardwareSurface (com.bitwig.extension.controller.api.HardwareSurface)2 InternalHardwareLightState (com.bitwig.extension.controller.api.InternalHardwareLightState)2 MultiStateHardwareLight (com.bitwig.extension.controller.api.MultiStateHardwareLight)2 HostImpl (de.mossgrabers.bitwig.framework.daw.HostImpl)2