Skip to content

Commit

Permalink
0.8. Support for native drum sequencer
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-hjalm committed Aug 25, 2018
1 parent 78667fd commit d164f09
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 50 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

<properties>
<bitwig.extension.directory>.</bitwig.extension.directory>
<!--<bitwig.extension.directory>C:\Users\axel\Documents\Bitwig Studio\Extensions</bitwig.extension.directory>-->

</properties>

Expand Down
50 changes: 29 additions & 21 deletions src/main/java/com/hjaxel/MidiFighterTwisterExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,10 @@ protected MidiFighterTwisterExtension(final MidiFighterTwisterExtensionDefinitio
@Override
public void init() {
host = getHost();
setupMidiChannels();

NoteInput drumSequencer = host.getMidiInPort(0).createNoteInput("MFT Drum Sequencer");
drumSequencer.setShouldConsumeEvents(false);

userControls = host.createUserControls(32);
for(int i = 0; i < 16; i++){
final int x = i;
Parameter parameter = userControls.getControl(i);
parameter.value().addValueObserver(128, val -> {
twister.value(16 + x, val);
});
}
for(int i = 16; i < 32; i++){
final int x = i;
Parameter parameter = userControls.getControl(i);
parameter.value().addValueObserver(128, val -> {
twister.color(x, val );
});
}
setupMidiChannels();
setupDrumSequencer();
createUserControl();

colorMap = new ColorMap();
UserSettings settings = createSettings(host.getPreferences());
Expand Down Expand Up @@ -107,12 +91,36 @@ public void init() {
host.showPopupNotification("Midi Fighter Twister Initialized");
}

private void setupDrumSequencer() {
NoteInput drumSequencer = host.getMidiInPort(0).createNoteInput("MFT Drum Sequencer");
drumSequencer.setShouldConsumeEvents(false);
}

private void createUserControl() {
userControls = host.createUserControls(32);

for(int i = 0; i < 16; i++){
final int x = i;
Parameter parameter = userControls.getControl(i);
parameter.value().addValueObserver(128, val -> {
twister.value(16 + x, val);
});
}
for(int i = 16; i < 32; i++){
final int x = i;
Parameter parameter = userControls.getControl(i);
parameter.value().addValueObserver(128, val -> {
twister.color(x, val );
});
}
}


private void setupMidiChannels() {
midiOut = host.getMidiOutPort(0);
MidiIn midiIn = host.getMidiInPort(0);
midiIn.setMidiCallback((ShortMidiMessageReceivedCallback) msg -> onMidi0(msg));
midiIn.setSysexCallback((String data) -> onSysex0(data));
midiIn.setMidiCallback((ShortMidiMessageReceivedCallback) this::onMidi0);
midiIn.setSysexCallback(this::onSysex0);
}

private UserSettings createSettings(Preferences preferences) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/hjaxel/MidiMessageParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,11 @@ private BitwigCommand toCommand(Encoder encoder, MidiMessage midiMessage, Consum

// Function toggles
case Device:
return () -> application.toggleDevices();
return () -> {};
case Drums:
return () -> {
};
return () -> {};
case Mixer:
return () -> application.toggleMixer();
return () -> {};

case GotoMixer:
case GotoMixer2:
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/com/hjaxel/page/drum/DrumPad16.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,11 @@ public class DrumPad16 extends MidiFighterTwisterControl {
private UserSettings settings;


private boolean isActive() {
return this.settings.isPage2DrumMode();
}

public DrumPad16(ControllerHost host, UserSettings settings) {
super(host, 16);
this.settings = settings;

if (isActive()) {
populateNoteToEncoderMap();
this.clip = host.createLauncherCursorClip(127, 127);

Expand All @@ -79,29 +75,23 @@ public DrumPad16(ControllerHost host, UserSettings settings) {

addPadListeners(host);

}

}

private void addPadListeners(ControllerHost host) {
if (isActive()) {
for (int i = LOW_NOTE; i <= HIGH_NOTE; i++) {
pads.put(i, new DrumSequencer(host, clip, i));
}
}
}

private void addNoteObserver() {
if (isActive()) {
PlayingNoteArrayValue playingNoteArrayValue = clip.getTrack().playingNotes();
playingNoteArrayValue.markInterested();
playingNoteArrayValue.setIsSubscribed(true);
playingNoteArrayValue.addValueObserver(this::noteObserver);
}
}

private void subscribeToClipEvents() {
if (isActive()) {
this.clip.setIsSubscribed(true);
this.clip.playingStep().markInterested();
this.clip.getPlayStart().markInterested();
Expand All @@ -113,19 +103,15 @@ private void subscribeToClipEvents() {
this.clip.getAccent().markInterested();
this.clip.canScrollStepsBackwards().markInterested();
this.clip.canScrollStepsForwards().markInterested();
}
}

private void populateNoteToEncoderMap() {
if (isActive()) {
for (int i = 0; i < 16; i++) {
noteToEncoder.put(encoderPadLookup[i], i + 16);
}
}
}

private void drawOverview() {
if(isActive()){
for (int i = 0; i < 16; i++) {
ringOff(i);
}
Expand All @@ -137,12 +123,10 @@ private void drawOverview() {
led(key, MidiFighterTwisterColor.INACTIVE_PAD);
}
*/
}

}

private void noteObserver(PlayingNote[] playingNotes) {
if(isActive()) {
if (overviewMode.get()) {
List<Integer> playing = new ArrayList<>();
for (PlayingNote playingNote : playingNotes) {
Expand All @@ -160,11 +144,9 @@ private void noteObserver(PlayingNote[] playingNotes) {
}
}
}
}
}

public void enableObservers(final boolean enable) {
if(isActive()) {
this.clip.playingStep().setIsSubscribed(enable);
this.clip.getPlayStart().setIsSubscribed(enable);
this.clip.getPlayStop().setIsSubscribed(enable);
Expand All @@ -173,26 +155,20 @@ public void enableObservers(final boolean enable) {
this.clip.isLoopEnabled().setIsSubscribed(enable);
this.clip.getShuffle().setIsSubscribed(enable);
this.clip.getAccent().setIsSubscribed(enable);
}
}

@Override
protected boolean accept(MidiMessage midiMessage) {
if(isActive()) {
for (MidiChannelAndRange midiChannelAndRange : observedMessages) {
if (midiChannelAndRange.accepts(midiMessage)) {
return handle(midiMessage);
}
}
}
return false;
}

private boolean handle(MidiMessage midiMessage) {

if (!settings.isPage2DrumMode()) {
return true;
}

switch (midiMessage.getChannel()) {
case CHANNEL_3:
Expand Down
Binary file added src/main/resources/MFTWB2_07.mfs
Binary file not shown.
Binary file added src/main/resources/MFTWB2_08.mfs
Binary file not shown.

0 comments on commit d164f09

Please sign in to comment.