|
8 | 8 | import com.bitwig.extension.controller.api.ClipLauncherSlotBank; |
9 | 9 | import com.bitwig.extension.controller.api.CursorTrack; |
10 | 10 | import com.bitwig.extension.controller.api.PinnableCursorClip; |
11 | | -import com.bitwig.extensions.debug.RemoteConsole; |
12 | 11 | import com.bitwig.extensions.framework.Layer; |
13 | 12 |
|
14 | 13 | public class SeqClipHandler { |
15 | 14 |
|
16 | | - private final DrumSequenceMode parent; |
17 | | - private final PinnableCursorClip cursorClip; |
18 | | - private int selectedSlotIndex = -1; |
19 | | - private final ClipLauncherSlotBank slotBank; |
20 | | - private final RgbLigthState[] slotColors = new RgbLigthState[16]; |
21 | | - private final CursorTrack cursorTrack; |
22 | | - private int blinkState = 0; |
| 15 | + private final DrumSequenceMode parent; |
| 16 | + private final PinnableCursorClip cursorClip; |
| 17 | + private int selectedSlotIndex = -1; |
| 18 | + private final ClipLauncherSlotBank slotBank; |
| 19 | + private final RgbLigthState[] slotColors = new RgbLigthState[16]; |
| 20 | + private final CursorTrack cursorTrack; |
| 21 | + private int blinkState = 0; |
23 | 22 |
|
24 | | - public SeqClipHandler(final AkaiFireDrumSeqExtension driver, final DrumSequenceMode parent, final Layer clipLayer) { |
25 | | - this.parent = parent; |
26 | | - this.cursorClip = parent.getCursorClip(); |
27 | | - cursorTrack = driver.getViewControl().getCursorTrack(); |
28 | | - slotBank = cursorTrack.clipLauncherSlotBank(); |
29 | | - initClipControlButtons(clipLayer, driver); |
30 | | - } |
| 23 | + public SeqClipHandler(final AkaiFireDrumSeqExtension driver, final DrumSequenceMode parent, final Layer clipLayer) { |
| 24 | + this.parent = parent; |
| 25 | + this.cursorClip = parent.getCursorClip(); |
| 26 | + cursorTrack = driver.getViewControl().getCursorTrack(); |
| 27 | + slotBank = cursorTrack.clipLauncherSlotBank(); |
| 28 | + initClipControlButtons(clipLayer, driver); |
| 29 | + } |
31 | 30 |
|
32 | | - private void initClipControlButtons(final Layer clipLayer, final AkaiFireDrumSeqExtension driver) { |
33 | | - final RgbButton[] rgbButtons = driver.getRgbButtons(); |
34 | | - for (int i = 0; i < 16; i++) { |
35 | | - final RgbButton button = rgbButtons[i + 16]; |
36 | | - final int index = i; |
| 31 | + private void initClipControlButtons(final Layer clipLayer, final AkaiFireDrumSeqExtension driver) { |
| 32 | + final RgbButton[] rgbButtons = driver.getRgbButtons(); |
| 33 | + for (int i = 0; i < 16; i++) { |
| 34 | + final RgbButton button = rgbButtons[i + 16]; |
| 35 | + final int index = i; |
37 | 36 |
|
38 | | - final ClipLauncherSlot cs = slotBank.getItemAt(index); |
| 37 | + final ClipLauncherSlot cs = slotBank.getItemAt(index); |
39 | 38 |
|
40 | | - cs.color().addValueObserver((r, g, b) -> { |
41 | | - slotColors[index] = ColorLookup.getColor(r, g, b); |
42 | | - }); |
43 | | - cs.isSelected().addValueObserver(selected -> { |
44 | | - if (selected) { |
45 | | - selectedSlotIndex = index; |
46 | | - } |
47 | | - }); |
48 | | - slotColors[index] = ColorLookup.getColor(cs.color().get()); |
49 | | - cs.exists().markInterested(); |
50 | | - cs.hasContent().markInterested(); |
51 | | - cs.isPlaybackQueued().markInterested(); |
52 | | - cs.isPlaying().markInterested(); |
53 | | - cs.isRecording().markInterested(); |
54 | | - cs.isRecordingQueued().markInterested(); |
55 | | - cs.isSelected().markInterested(); |
56 | | - cs.isStopQueued().markInterested(); |
| 39 | + cs.color().addValueObserver((r, g, b) -> { |
| 40 | + slotColors[index] = ColorLookup.getColor(r, g, b); |
| 41 | + }); |
| 42 | + cs.isSelected().addValueObserver(selected -> { |
| 43 | + if (selected) { |
| 44 | + selectedSlotIndex = index; |
| 45 | + } |
| 46 | + }); |
| 47 | + slotColors[index] = ColorLookup.getColor(cs.color().get()); |
| 48 | + cs.exists().markInterested(); |
| 49 | + cs.hasContent().markInterested(); |
| 50 | + cs.isPlaybackQueued().markInterested(); |
| 51 | + cs.isPlaying().markInterested(); |
| 52 | + cs.isRecording().markInterested(); |
| 53 | + cs.isRecordingQueued().markInterested(); |
| 54 | + cs.isSelected().markInterested(); |
| 55 | + cs.isStopQueued().markInterested(); |
57 | 56 |
|
58 | | - button.bindPressed(clipLayer, p -> handleClip(index, cs, p), () -> getClipSate(index, cs)); |
59 | | - } |
60 | | - } |
| 57 | + button.bindPressed(clipLayer, p -> handleClip(index, cs, p), () -> getClipSate(index, cs)); |
| 58 | + } |
| 59 | + } |
61 | 60 |
|
62 | | - private RgbLigthState getClipSate(final int index, final ClipLauncherSlot slot) { |
63 | | - if (slot.hasContent().get()) { |
64 | | - if (slotColors[index] == null) { |
65 | | - return RgbLigthState.OFF; |
66 | | - } |
67 | | - final RgbLigthState color = slotColors[index]; |
68 | | - if (slot.isSelected().get()) { |
| 61 | + private RgbLigthState getClipSate(final int index, final ClipLauncherSlot slot) { |
| 62 | + if (slot.hasContent().get()) { |
| 63 | + if (slotColors[index] == null) { |
| 64 | + return RgbLigthState.OFF; |
| 65 | + } |
| 66 | + final RgbLigthState color = slotColors[index]; |
| 67 | + if (slot.isSelected().get()) { |
69 | 68 |
|
70 | | - if (slot.isPlaying().get()) { |
71 | | - return blinkSlow(color.getBrightest(), color); |
72 | | - } |
73 | | - if (slot.isPlaybackQueued().get()) { |
74 | | - return blinkFast(color.getBrightest(), color.getDimmed()); |
75 | | - } |
76 | | - return color.getBrightend(); |
77 | | - } else { |
78 | | - if (slot.isPlaying().get()) { |
79 | | - return blinkSlow(color, color.getDimmed()); |
80 | | - } |
81 | | - if (slot.isPlaybackQueued().get()) { |
82 | | - return blinkFast(color, color.getDimmed()); |
83 | | - } |
84 | | - return color.getDimmed(); |
85 | | - } |
86 | | - } |
87 | | - return RgbLigthState.OFF; |
88 | | - } |
| 69 | + if (slot.isPlaying().get()) { |
| 70 | + return blinkSlow(color.getBrightest(), color); |
| 71 | + } |
| 72 | + if (slot.isPlaybackQueued().get()) { |
| 73 | + return blinkFast(color.getBrightest(), color.getDimmed()); |
| 74 | + } |
| 75 | + return color.getBrightend(); |
| 76 | + } else { |
| 77 | + if (slot.isPlaying().get()) { |
| 78 | + return blinkSlow(color, color.getDimmed()); |
| 79 | + } |
| 80 | + if (slot.isPlaybackQueued().get()) { |
| 81 | + return blinkFast(color, color.getDimmed()); |
| 82 | + } |
| 83 | + return color.getDimmed(); |
| 84 | + } |
| 85 | + } |
| 86 | + return RgbLigthState.OFF; |
| 87 | + } |
89 | 88 |
|
90 | | - private RgbLigthState blinkSlow(final RgbLigthState on, final RgbLigthState off) { |
91 | | - if (blinkState % 8 < 4) { |
92 | | - return on; |
93 | | - } |
94 | | - return off; |
95 | | - } |
| 89 | + private RgbLigthState blinkSlow(final RgbLigthState on, final RgbLigthState off) { |
| 90 | + if (blinkState % 8 < 4) { |
| 91 | + return on; |
| 92 | + } |
| 93 | + return off; |
| 94 | + } |
96 | 95 |
|
97 | | - private RgbLigthState blinkFast(final RgbLigthState on, final RgbLigthState off) { |
98 | | - if (blinkState % 2 == 0) { |
99 | | - return on; |
100 | | - } |
101 | | - return off; |
102 | | - } |
| 96 | + private RgbLigthState blinkFast(final RgbLigthState on, final RgbLigthState off) { |
| 97 | + if (blinkState % 2 == 0) { |
| 98 | + return on; |
| 99 | + } |
| 100 | + return off; |
| 101 | + } |
103 | 102 |
|
104 | | - private void handleClip(final int index, final ClipLauncherSlot slot, final boolean pressed) { |
105 | | - if (!pressed) { |
106 | | - return; |
107 | | - } |
108 | | - final boolean hasContent = slot.hasContent().get(); |
109 | | - if (hasContent) { |
110 | | - if (parent.isDeleteHeld()) { |
111 | | - if (parent.isShiftHeld()) { // SHIFT + DELETE => remove clip |
112 | | - slot.deleteObject(); |
113 | | - } else { // SHIFT + DELETE => clear all steps |
114 | | - final int previous = selectedSlotIndex; |
115 | | - slot.select(); |
116 | | - cursorClip.clearSteps(); |
117 | | - if (previous != -1) { |
118 | | - slotBank.getItemAt(previous).select(); |
119 | | - } |
120 | | - } |
121 | | - } else if (parent.isCopyHeld()) { // copies note |
122 | | - RemoteConsole.out.println("Copy Clip ", selectedSlotIndex); |
123 | | - if (selectedSlotIndex != -1 && selectedSlotIndex != index) { |
124 | | - slot.replaceInsertionPoint().copySlotsOrScenes(slotBank.getItemAt(selectedSlotIndex)); |
125 | | - } |
126 | | - } else if (parent.isSelectHeld()) { |
127 | | - slot.select(); |
128 | | - } else { |
129 | | - slot.select(); |
130 | | - slot.launch(); |
131 | | - } |
132 | | - } else { |
133 | | - if (parent.isCopyHeld()) { |
134 | | - if (selectedSlotIndex != -1 && selectedSlotIndex != index) { |
135 | | - RemoteConsole.out.println("Copy Clip ", index); |
136 | | - slot.replaceInsertionPoint().copySlotsOrScenes(slotBank.getItemAt(selectedSlotIndex)); |
137 | | - } |
138 | | - } else { |
139 | | - slot.createEmptyClip(4); |
140 | | - } |
141 | | - } |
142 | | - } |
| 103 | + private void handleClip(final int index, final ClipLauncherSlot slot, final boolean pressed) { |
| 104 | + if (!pressed) { |
| 105 | + return; |
| 106 | + } |
| 107 | + final boolean hasContent = slot.hasContent().get(); |
| 108 | + if (hasContent) { |
| 109 | + if (parent.isDeleteHeld()) { |
| 110 | + if (parent.isShiftHeld()) { // SHIFT + DELETE => remove clip |
| 111 | + slot.deleteObject(); |
| 112 | + } else { // SHIFT + DELETE => clear all steps |
| 113 | + final int previous = selectedSlotIndex; |
| 114 | + slot.select(); |
| 115 | + cursorClip.clearSteps(); |
| 116 | + if (previous != -1) { |
| 117 | + slotBank.getItemAt(previous).select(); |
| 118 | + } |
| 119 | + } |
| 120 | + } else if (parent.isCopyHeld()) { // copies note |
| 121 | + if (selectedSlotIndex != -1 && selectedSlotIndex != index) { |
| 122 | + slot.replaceInsertionPoint().copySlotsOrScenes(slotBank.getItemAt(selectedSlotIndex)); |
| 123 | + } |
| 124 | + } else if (parent.isSelectHeld()) { |
| 125 | + slot.select(); |
| 126 | + } else { |
| 127 | + slot.select(); |
| 128 | + slot.launch(); |
| 129 | + } |
| 130 | + } else { |
| 131 | + if (parent.isCopyHeld()) { |
| 132 | + if (selectedSlotIndex != -1 && selectedSlotIndex != index) { |
| 133 | + slot.replaceInsertionPoint().copySlotsOrScenes(slotBank.getItemAt(selectedSlotIndex)); |
| 134 | + } |
| 135 | + } else { |
| 136 | + slot.createEmptyClip(4); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
143 | 140 |
|
144 | | - public void notifyBlink(final int blinkState) { |
145 | | - this.blinkState = blinkState; |
146 | | - } |
| 141 | + public void notifyBlink(final int blinkState) { |
| 142 | + this.blinkState = blinkState; |
| 143 | + } |
147 | 144 |
|
148 | 145 | } |
0 commit comments