Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Pioneer DDJ-SB2 mapping for Mixxx 2.1 #1243

Merged
merged 27 commits into from
Jul 5, 2017

Conversation

Be-ing
Copy link
Contributor

@Be-ing Be-ing commented Apr 27, 2017

Update Pioneer DDJ-SB2 for new effects and looping UIs in Mixxx 2.1 and fix various other issues. New mappings for autoloop pad layer and effects are documented on the wiki.

I did this while I was staying with a friend who happened to have a DDJ-SB2. I do not have access to the device to test further changes.

It would be nice to finish rewriting this using Components, but I did not have time to do that.

Depends on:

Be-ing added 9 commits April 27, 2017 10:19
Button LEDs indicate the focused effect
short press effect button: focus that effect, or unfocus if it is
already focused.
long press effect button: toggle enable switch for that effect
knob: control metaknob of focused effect or dry/wet if no effect is
focused

Update copyright notice because Components is licensed under GPL
* make vinyl/slip button only show status of vinyl or slip mode,
depending on invertVinylSlipButton option. Also make slip button a
momentary instead of toggle switch button.
* do not show status of quantize on sync button LED when shift is
pressed

This commit removes MIDI output for play, cue, and sync buttons, but
that is restored in the next commit.
clean up code for gain, EQ, QuickEffect knobs plus play, cue, and sync
buttons
from left to right:
beatloop_toggle, shift beatlooproll_activate
beatloop_halve, shift loop_move_backward
beatloop_double, shift loop_move_forward
reloop_toggle, shift reloop_andstop
I have not had a chance to test this. If this does anything, I presume
it queries the controller for the position of potentiometers on startup.
@Be-ing Be-ing mentioned this pull request May 7, 2017
Be-ing added 2 commits May 8, 2017 14:57
I have not actually tested this because I no longer have access
to a DDJ-SB2. The 0x9B, 0x08, 0x7F message works for requesting
the potentiometer positions on the DDJ-SX, so hopefully it works
for the DDJ-SB2 as well.
@Be-ing Be-ing mentioned this pull request May 10, 2017
@Be-ing Be-ing mentioned this pull request May 25, 2017
3 tasks
@daschuer
Copy link
Member

Who is able to review this?

@Be-ing
Copy link
Contributor Author

Be-ing commented May 25, 2017

@nikmartin, @DJMaxergy, or @dg3nec, could one of you test this?

@nikmartin
Copy link
Contributor

Absolutely, just pulled out my SB2 and will test today. This issue states that it's dependent on #1127 and #1187. Should I merge those two PRs into master to test this? Since #1151 is now in master, do I need to do anything to make Tango use the new controls in PR #1187? I want to make sure I have my test environment setup correctly.

@Be-ing
Copy link
Contributor Author

Be-ing commented May 26, 2017

Both PRs this depended on have been merged to master. You can test it with the version of Tango in master, but you won't see the beatloop_size or beatjump_size on screen unless you use #940.

@Be-ing
Copy link
Contributor Author

Be-ing commented May 26, 2017

@nikmartin, can you report whether Mixxx loads the positions of the knobs and faders of the controller on startup? If so, please try commenting out lines 183 and 184 in the JS file, one line at a time, to test which one of those lines is working. Put // in front of the line to comment it out.

@Be-ing Be-ing force-pushed the ddj_sb2_mapping branch from 64e4044 to 7341577 Compare May 28, 2017 22:27
@nikmartin
Copy link
Contributor

I loaded a track that has hotcues immediately on startup, and the first three pads lit, corresponding to the three hotcues in the track. Also, the hotcues work properly right after loading.

@Be-ing
Copy link
Contributor Author

Be-ing commented May 31, 2017

Okay, so sending those MIDI messages does change the MIDI messages the controller sends when the pads are pressed. We could add an easy to configure user preference to pick the pad mode to set the controller to on startup. However, I think it would be better to avoid changing it on shutdown. In the shutdown function, try replacing:

    for (var channel = 0; channel <= 10; channel++) {
        for (var control = 0; control <= 127; control++) {
            // skip deck toggle buttons for now
            if (control === 0x72) {
                continue;
            }
            midi.sendShortMsg(0x90 + channel, control, 0);
        }
    }

with this:

    var skip = [0x72, 0x1B, 0x69, 0x1E, 0x6B, 0x20, 0x6D, 0x22, 0x6F, 0x70, 0x75];
    for (var channel = 0; channel <= 10; channel++) {
        for (var control = 0; control <= 127; control++) {
            // skip deck toggle buttons and pad mode buttons
            if (skip.indexOf(control) > -1) {
                continue;
            }
            midi.sendShortMsg(0x90 + channel, control, 0);
        }
    }

and remove the code I posted above from the init function. Hopefully the pad mode when Mixxx restarts will remain the same as it was when Mixxx was last shut down.

@nikmartin
Copy link
Contributor

OK, now on shutdown, everything 'cleans up' and the controller is left in a nominal state.

@nikmartin
Copy link
Contributor

Another not so small change is that shift+play used to reverse the track only while the play button was depressed. Now, it stays reversed until you release and hit play again. Can that be changed into an option in the script header? I use that function pretty heavily to censor tracks that I don't have a clean version of, and now it's not very easy to use when you are back masking over a single bad word.

@nikmartin
Copy link
Contributor

I wrote a VERY close approximation of the native Pad Trans effect in the SB2. It's actually wired to the padtrans key in the midi xml, so the implementation below is hard coded to 1/8 of a beat. I think I may replace the Pads - kill (shift + manual loop) to see how it works in practice. If the pad trans wasn;t a proprietary non-midi control, we could use it as an on / off, but it takes over the pads midi values when it's on.

PioneerDDJSB2.ptMuted = [false,false];
PioneerDDJSB2.padTrans = function(channel, control, value, status, group){
    print('channel: ' + channel + ' control: ' + control + ' value: ' + value + ' status: ' + status + ' group: ' + group);
    var bpm = engine.getValue(group,'bpm');
    /**
    * transRate is how often to toggle the effect per BEAT (not second)
    * To calculate, take the bpm and divide by 60 (secs), to get how many beats per second
    * then, divide 1000 msec by that. and you get the interval in msec of one beat. The last calculation 
    * is to divide the interval by how many times per beat you want the effect. The stock SB2 does 1, 1/2, 1/4, and 1/8 of a beat
    * lets take a 128 bpm song for example:
    * 128 / 60 = 2.13 Beats per Second
    * 1000 / 2.13 = 468.75 is how many msec 1 beat is.
    */
    var transRate = (1000/(bpm/60))/16; // <<< hard coded to 1/8 beat right now
    if (value===0){
        engine.stopTimer(PioneerDDJSB2.pttimer);
        engine.setValue(group, 'mute', 0);
        return;
    }

    PioneerDDJSB2.pttimer = engine.beginTimer(transRate, function(){
              engine.setValue(group, 'mute', PioneerDDJSB2.ptMuted[channel]); 
             PioneerDDJSB2.ptMuted[channel] = !PioneerDDJSB2.ptMuted[channel];   
    }, false);
};

@Be-ing
Copy link
Contributor Author

Be-ing commented Jun 1, 2017

OK, now on shutdown, everything 'cleans up' and the controller is left in a nominal state.

When you start Mixxx again, is the pad mode the same as when Mixxx shut down?

Another not so small change is that shift+play used to reverse the track only while the play button was depressed. Now, it stays reversed until you release and hit play again. Can that be changed into an option in the script header? I use that function pretty heavily to censor tracks that I don't have a clean version of, and now it's not very easy to use when you are back masking over a single bad word.

Hmm, could that be fit into the mapping elsewhere? Maybe shift + Pad Trans? That could get tricky though. I think the mapping would have to track the active pad mode and reset it to the last mode when shift + Pad Trans was released.

I wrote a VERY close approximation of the native Pad Trans effect in the SB2. It's actually wired to the padtrans key in the midi xml, so the implementation below is hard coded to 1/8 of a beat. I think I may replace the Pads - kill (shift + manual loop) to see how it works in practice. If the pad trans wasn;t a proprietary non-midi control, we could use it as an on / off, but it takes over the pads midi values when it's on.

Proprietary non-MIDI control? It's a USB MIDI class compliant device. Do you mean the pads send different MIDI messages when Pad Trans is active? That's how the other pad modes work. I don't see those MIDI codes listed in Pioneer's documentation though, so it would be up to you to map those. You could make a pull request for my ddj_sb2_mapping branch, or we could merge this, then you could make another pull request for the master branch of this repository.

@nikmartin
Copy link
Contributor

When you start Mixxx again, is the pad mode the same as when Mixxx shut down?

Upon further debugging, on shutdown, almost everything is reset to nominal with just the hotcue button on, and it comes up that same way. It does reset the vinyl mode, but that's a javascript variable. If the Shift + Manual Loop light is blinking, it remains that way when mixxx exits, and when restarted, everything is set back to a nominal state.

Proprietary non-MIDI control? It's a USB MIDI class compliant device.

It is, except for the pad-trans button. it sends

Debug [Controller]: "DDJ-SB2 MIDI 1: t:4008244 ms status 0x90 (ch 1, opcode 0x9), ctrl 0x70, val 0x00"

On channel 1, BUT it somehow short circuits the performance pads 1-4. While the padTrans button is enabled, pads 1-4 (top row ) all send:

Debug [Controller]: "DDJ-SB2 MIDI 1: t:4140176 ms status 0xB0 (ch 1, opcode 0xB), ctrl 0x13, val 0x27"
Debug [Controller]: "DDJ-SB2 MIDI 1: t:4140176 ms status 0xB0 (ch 1, opcode 0xB), ctrl 0x33, val 0x00"

And only send that when they are released. There's a lot of grumbling about this over at Traktor. In fact, if you start Serato once, use the pad trans effects, then exit and start mixxx, the pad trans effect works until you unplug the controller. The effect is actually loaded in the controller until it's unplugged.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jun 1, 2017

Hmm, that's strange. Maybe when the Pad Trans button is pressed Serato sends the controller a MIDI message that sets the controller to a state where it sends distinct messages for each pad. I doubt they went so far out of their way to use something that isn't a standard MIDI message. Perhaps that mysterious "DJ App Connect" message has something to do with it. If you want to get that to work, I suggest using MIDI Monitor (Mac) or MIDI OX (Windows) to intercept the MIDI messages that Serato sends to the controller. From Pioneer support, apparently Serato sends the controller a message with the tempo, then the controller firmware uses that to send volume on/off MIDI messages repeatedly when a pad is pressed in Pad Trans mode.

@nikmartin
Copy link
Contributor

Yes, my guess is that since the effect works after being disconnected from Serato and connected to mixxx, that the effect is actually being done in the soundcard on the SB2, and the performance pads are no longer sending valid midi messages when the PAd Trans button is on.. You SB2 mapping is quite well written, but I'm having a time finding an unused latching button (like the Shift+Manual Loop button) that will let me add this effect to the mapping. I know that the Filter Kill effect commands are now deprecated in lieu of the Effects framework, but I don't want to get rid of them until the commands are actually removed from mixxx. Any other ideas for an unused Shift + Button combo?

@Be-ing
Copy link
Contributor Author

Be-ing commented Jun 1, 2017

the effect is actually being done in the soundcard on the SB2

I think it's highly unlikely that Pioneer put audio DSP inside the DDJ-SB2. That would be a huge waste of money for them. It doesn't even have an analog-to-digital converter for the microphone input. From this video, it looks like the firmware makes the effect just by sending messages as if the volume fader was jumping up/down really fast, like how the filter fade feature sends MIDI messages as if the filter knobs are being turned. Getting Pad Trans to work might be as simple as figuring out the MIDI message Serato sends to the controller to tell it the tempo to use.

@nikmartin
Copy link
Contributor

Agreed, the effect itself is pretty simple, so that's probably it. My implementation works pretty well, but the timer api will drift out of sync after a while, but longer than you'd actually use the effect. My initial thought was to try to do it using the mixxx effects chain, assigning the effect to a high numbered effects slot, but couldn't grok the effects framework to figure it out.

@nikmartin
Copy link
Contributor

You could make a pull request for my ddj_sb2_mapping branch, or we could merge this, then you could make another pull request for the master branch of this repository.

Let me debug it a bit more and make it deck independent and find an unused effect enable key in the mapping, and I'll do a pull request

@Be-ing
Copy link
Contributor Author

Be-ing commented Jun 1, 2017

While the padTrans button is enabled, pads 1-4 (top row ) all send:

Debug [Controller]: "DDJ-SB2 MIDI 1: t:4140176 ms status 0xB0 (ch 1, opcode 0xB), ctrl 0x13, val 0x27"
Debug [Controller]: "DDJ-SB2 MIDI 1: t:4140176 ms status 0xB0 (ch 1, opcode 0xB), ctrl 0x33, val 0x00"

Those are the MIDI messages for the deck volume fader (it uses 2 MIDI messages, one for a least significant byte and another for a most significant byte).

@Be-ing
Copy link
Contributor Author

Be-ing commented Jun 1, 2017

Let me debug it a bit more and make it deck independent and find an unused effect enable key in the mapping, and I'll do a pull request

I think it would be a better idea to figure out how Serato communicates the tempo to the controller and work with how the controller is designed.

@sblaisot
Copy link
Member

sblaisot commented Jun 1, 2017

@Be-ing Be-ing force-pushed the ddj_sb2_mapping branch from a98fa38 to 95f2e4a Compare June 1, 2017 21:26
@Be-ing
Copy link
Contributor Author

Be-ing commented Jun 2, 2017

@dec0de can you confirm that the issue with the pad mode on startup has been fixed with the latest commit?

#940 has been merged to master so you can just compile this branch now without having to merge anything else.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 4, 2017

@nikmartin: I added an option to use shift + cue for reverseroll like it was mapped in Mixxx 2.0.

Are there any issues remaining? Ready for merge? If someone who has the controller wants to implement the Pad Trans functionality, I think that should be done in a new PR after merging this.

@nikmartin
Copy link
Contributor

nikmartin commented Jul 5, 2017

@Be-ing I will test heavily the next few days, and open new issues that I find (Edit: My opinion is that it's ready to merge as-is). I will also make an attempt at the Pad Trans effect and do a PR based on master after this is merged. Based on your earlier reply to my comment about what the controller is sending on pad trans + effect buttons, the effect seems to rely on the controller knowing the BPM of the song, and the rapid volume switches are in sync with the bpm. My attempt is just using the bpm from the track, but is not synced in any way. I'm not sure that that is available to javascript from the mixxx engine. I don't think the controller has any DSP capability, but does seem to possibly know how to do beat detection? Not sure yet.

@Be-ing
Copy link
Contributor Author

Be-ing commented Jul 5, 2017

@daschuer: could you merge this?

@nikmartin: I doubt the controller has any way to detect the beat. It probably gets that information from Serato with some undocumented MIDI message. You'd have to intercept the MIDI messages from Serato to find that. Mixxx does make the BPM available to controller mappings through the "bpm" Control.

@daschuer
Copy link
Member

daschuer commented Jul 5, 2017

Thank you for all the work. And for reviewing this.

@daschuer daschuer merged commit d43d2e7 into mixxxdj:master Jul 5, 2017
@Be-ing Be-ing deleted the ddj_sb2_mapping branch September 16, 2017 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants