All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.dmx.client.model.DmxSceneryModel Maven / Gradle / Ivy

The newest version!
package org.bidib.wizard.dmx.client.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bidib.wizard.api.model.NodeInterface;
import org.bidib.wizard.dmx.client.event.DmxChannelWrapperEvent;
import org.bidib.wizard.dmx.client.event.DmxTimelineWrapperEvent;
import org.bidib.wizard.model.dmx.DmxChannelWrapper;
import org.bidib.wizard.model.dmx.DmxDimmer;

import com.jgoodies.binding.beans.Model;

import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
import io.reactivex.rxjava3.subjects.PublishSubject;
import io.reactivex.rxjava3.subjects.Subject;

/**
 * The DmxSceneryModel holds all information of the selected node that is needed for DMX modelling. It has
 * a list of the DmxScenery instances.
 */
public class DmxSceneryModel extends Model implements DmxEnvironmentProvider {

    private static final long serialVersionUID = 1L;

    public static final String PROPERTY_SCENERIES = "sceneries";

    public static final String PROPERTY_DIMMERS = "dimmers";

    public static final String PROPERTY_HAS_PENDING_CHANGES = "hasPendingChanges";

    public static final int MAX_CONFIGURED_DIMMERS = 5;

    public static final int MAX_CONFIGURED_CHANNELS = 6;

    public static final int DIMMER_GAP = 13;

    public static final int CV_CONFIGURED_DIMMERS = 1710;

    // public static final int CV_CONFIGURED_DIMMERS_V2 = 1678;

    public static final int CV_CONFIGURED_DIMMER_0_CHANNELS = CV_CONFIGURED_DIMMERS + 1;

    // public static final int CV_CONFIGURED_DIMMER_0_CHANNELS_V2 = CV_CONFIGURED_DIMMERS_V2 + 1;

    public static final int CV_CONFIGURED_DIMMER_0_CHANNEL_COLORS_START = CV_CONFIGURED_DIMMERS + 2;

    // public static final int CV_CONFIGURED_DIMMER_0_CHANNEL_COLORS_START_V2 = CV_CONFIGURED_DIMMERS_V2 + 2;

    public static final int TOTAL_AVAILABLE_CHANNELS = 32; // 8 * 4

    public static final int TOTAL_AVAILABLE_TICKS = 24;

    public static final int TICKS_CV_START = 120;

    // DMX channel R 1
    public static final int FIRST_DMX_CHANNEL_CV_START = 808;

    public static final int FIRST_DMX_CHANNEL_CV_START_V2 = 776;

    // DMX channel G 1
    public static final int SECOND_DMX_CHANNEL_CV_START = 834;

    public static final int SECOND_DMX_CHANNEL_CV_START_V2 = 802;

    // gap between the channels
    public static final int DMX_CHANNEL_CV_GAP = SECOND_DMX_CHANNEL_CV_START - FIRST_DMX_CHANNEL_CV_START;

    // public static final int DMX_CHANNEL_CV_GAP_V2 = SECOND_DMX_CHANNEL_CV_START - FIRST_DMX_CHANNEL_CV_START;

    public static final int OVERLAY_CV_START = 616;

    public static final int OVERLAY_CV_COUNT = 48;

    public static final int OVERLAY_CV_COUNT_FW2 = 40;

    public static final int FIXED_PATTERN_CV_START = 232;

    public static final int FIXED_PATTERN_CV_COUNT = 64;

    private final NodeInterface node;

    private List sceneries = new ArrayList<>();

    private List dimmers = new ArrayList<>();

    private final Map> dmxDimmerToDmxDataRowMap = new HashMap<>();

    private final Map> configuredDmxChannelsMap = new HashMap<>();

    private final Subject subjectDmxChannelEvents;

    private final Subject subjectDmxTimelineEvents;

    private final BehaviorSubject subjectHasPendingChanges;

    public DmxSceneryModel(final NodeInterface node) {
        this.node = node;

        this.subjectDmxChannelEvents = PublishSubject.create();
        this.subjectDmxTimelineEvents = PublishSubject.create();
        this.subjectHasPendingChanges = BehaviorSubject.create();
        // set the initial value
        this.subjectHasPendingChanges.onNext(false);
    }

    public NodeInterface getNode() {
        return node;
    }

    public Disposable subscribeHasPendingChangesEvents(
        Consumer onNext, Consumer onError, Action onComplete) {

        return this.subjectHasPendingChanges.subscribe(onNext, onError, onComplete);
    }

    /**
     * Set the has pending changes flag
     * 
     * @param hasPendingChanges
     *            the has pending changes flag
     */
    public void setHasPendingChanges(boolean hasPendingChanges) {
        boolean oldValue = isHasPendingChanges();
        this.subjectHasPendingChanges.onNext(hasPendingChanges);

        firePropertyChange(PROPERTY_HAS_PENDING_CHANGES, oldValue, hasPendingChanges);
    }

    public boolean isHasPendingChanges() {
        return this.subjectHasPendingChanges.getValue();
    }

    public Disposable subscribeDmxChannelEvents(
        Consumer onNext, Consumer onError, Action onComplete) {

        return this.subjectDmxChannelEvents.subscribe(onNext, onError, onComplete);
    }

    public void publishDmxChannelEvent(final DmxChannelWrapperEvent event) {
        this.subjectDmxChannelEvents.onNext(event);
    }

    public Disposable subscribeDmxTimelineEvents(
        Consumer onNext, Consumer onError, Action onComplete) {

        return this.subjectDmxTimelineEvents.subscribe(onNext, onError, onComplete);
    }

    public void publishDmxTimelineEvent(final DmxTimelineWrapperEvent event) {
        this.subjectDmxTimelineEvents.onNext(event);
    }

    /**
     * @return the sceneries
     */
    public List getSceneries() {
        return Collections.unmodifiableList(sceneries);
    }

    /**
     * @param scenery
     *            the scenery to add
     */
    public void addScenery(DmxScenery scenery) {
        List oldValue = new ArrayList<>(this.sceneries);

        this.sceneries.add(scenery);

        firePropertyChange(PROPERTY_SCENERIES, oldValue, sceneries);
    }

    /**
     * @param scenery
     *            the scenery to remove
     */
    public void removeScenery(DmxScenery scenery) {
        List oldValue = new ArrayList<>(this.sceneries);

        this.sceneries.remove(scenery);

        firePropertyChange(PROPERTY_SCENERIES, oldValue, sceneries);
    }

    /**
     * @param sceneries
     *            the sceneries to set
     */
    public void setSceneries(List sceneries) {
        List oldValue = new ArrayList<>(this.sceneries);

        this.sceneries.clear();
        this.sceneries.addAll(sceneries);

        firePropertyChange(PROPERTY_SCENERIES, oldValue, sceneries);
    }

    public List getDimmers() {
        return dimmers;
    }

    public void setDimmers(final List dimmers) {
        List oldValue = new ArrayList<>(this.dimmers);

        this.dimmers = dimmers;

        firePropertyChange(PROPERTY_DIMMERS, oldValue, dimmers);

    }

    public void addDmxDimmer(final DmxDimmer dimmer) {
        List oldValue = this.dimmers;

        List dimmers = new ArrayList<>(this.dimmers);
        dimmers.add(dimmer);
        this.dimmers = dimmers;

        firePropertyChange(PROPERTY_DIMMERS, oldValue, dimmers);
    }

    public void addDmxDataRows(final DmxDimmer dimmer, final List dmxDataRows) {

        this.dmxDimmerToDmxDataRowMap.put(dimmer, dmxDataRows);
    }

    public List getDmxDataRows(final DmxDimmer dimmer) {
        return this.dmxDimmerToDmxDataRowMap.get(dimmer);
    }

    @Override
    public Map> getConfiguredDmxChannelsMap() {
        return configuredDmxChannelsMap;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy