stoonoon / hxsMidiSwitcher

Simple 8 button MIDI controller for Line 6 HX Stomp using Nano clone
14 stars 4 forks source link

Long Press action missing? #2

Closed gobbersbubbus closed 2 years ago

gobbersbubbus commented 2 years ago

Hey @stoonoon!

I was building this switcher and I don't have the function to long press the tap tempo to access the tuner?

I dont have the display so im not sure if I am missing it there, but do you have the code that allows the long press to work?

I think you can access it by pushing multiple buttons butI would prefer to have it as the long press on the tuner?

Do you have the code for that and where to drop in?

Thank you!

stoonoon commented 2 years ago

I'm fairly sure it used to work - but at the moment I'm just on my phone and trying to reacquaint myself with years old code is a bit of a challenge.... It looks like it's at least part there, so my best guess at the moment would be that at some point I redesigned my menu page layout and missed off the case statements for long presses.... I think it's setup so case 0 to 7 were single short press actions and 8 to 15 would be long press. Hopefully that should be enough to get you started.... If not, let us know and I'll see what I can work out when I'm next at a desktop

gobbersbubbus commented 2 years ago

WOW THAT WAS FAST. I fully planned on waiting a week to hear from you!

That is promising, I can try to look at it, but I’m almost looking at hieroglyphics here ha ha.

This is for the Arduino Nano which I believe only has 12 digital pins? Does that mean pins 0-7 are single short press and 8-12 would be long press?

(I’m so sorry if this is a dumb question…)

Thank you

On May 9, 2022, at 4:23 PM, Stuart Noon @.***> wrote:

 I'm fairly sure it used to work - but at the moment I'm just on my phone and trying to reacquaint myself with years old code is a bit of a challenge.... It looks like it's at least part there, so my best guess at the moment would be that at some point I redesigned my menu page layout and missed off the case statements for long presses.... I think it's setup so case 0 to 7 were single short press actions and 8 to 15 would be long press. Hopefully that should be enough to get you started.... If not, let us know and I'll see what I can work out when I'm next at a desktop

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

stoonoon commented 2 years ago

The number for "nextCommand" isn't directly linked to the pin number on the Arduino. It's just an arbitrary variable that acts as a menu of possible midi actions... 0 to 7 on that list do happen to map to the footswitches - and they are used for the short press actions for each one. If a long press is detected, the readButtons function sets the nextCommand variable to (pin number + number of switches)... And so long presses would use the next 8 options in the "menu". Hope that makes sense.

If you look at line 311-313 you'll see: case 7: MIDI.sendControlChange(53,0,1); //FS5 break;

If you add an extra 3 lines immediately after those but instead with :

case 8: MIDI.sendControlChange(68,68,1); //tuner break;

I think that might do it....

gobbersbubbus commented 2 years ago

I think I understand, thank you!

Sorry, last question, if I wanted to add a long press function to FS4 or FS5, where would I input those midi cc codes? Of is that possible?

Thank you!

On May 9, 2022, at 5:01 PM, Stuart Noon @.***> wrote:

 The number for "nextCommand" isn't directly linked to the pin number on the Arduino. It's just an arbitrary variable that acts as a menu of possible midi actions... 0 to 7 on that list do happen to map to the footswitches - and they are used for the short press actions for each one. If a long press is detected, the readButtons function sets the nextCommand variable to (pin number + number of switches)... And so long presses would use the next 8 options in the "menu". Hope that makes sense.

If you look at line 311-313 you'll see: case 7: MIDI.sendControlChange(53,0,1); //FS5 break;

If you add an extra 3 lines immediately after those but instead with :

case 8: MIDI.sendControlChange(68,68,1); //tuner break;

I think that might do it....

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

stoonoon commented 2 years ago

Do you mean long press the 4th/5th switch on your switcher? just add another 3 lines like before but with the first line being "case 11:" for FS4 long press or "case 12:" for FS5 long press.... so, for example:

case 11: //<- this bit signifies a long press on the 4th switch MIDI.sendControlChange(69,9,1); //<- this is the command for previous snapshot break; // <- this just signifies the end of the "case" statement

case 12: // < - this bit signifies switch a long press on the 5th switch MIDI.sendControlChange(69,8,1); // < - this is the command for next snapshot break;

or did you mean to be able to use FS4 and FS5 on the stomp? In which case you could use:

case 4: // <- this means a short press on the 5th switch MIDI.sendControlChange(52,0,1); // <- this is the command for FS4 on the stomp break;

case 5: // <- this means a short press on the 6th switch MIDI.sendControlChange(53,0,1); // <- this is the command for FS5 on the stomp break;

Does that help?

gobbersbubbus commented 2 years ago

Hey Stoo!

I really appreciate your help with all of this!

I had one more question if you had a moment…

Would you have the code to add a potentiometer/expression pedal to this code?

I appreciate it!

On May 10, 2022, at 1:03 PM, Stuart Noon @.***> wrote:

 Do you mean long press the 4th/5th switch on your switcher? just add another 3 lines like before but with the first line being "case 11:" for FS4 long press or "case 12:" for FS5 long press.... so, for example:

case 11: //<- this bit signifies a long press on the 4th switch MIDI.sendControlChange(69,9,1); //<- this is the command for previous snapshot break; // <- this just signifies the end of the "case" statement

case 12: // < - this bit signifies switch a long press on the 5th switch MIDI.sendControlChange(69,8,1); // < - this is the command for next snapshot break;

or did you mean to be able to use FS4 and FS5 on the stomp? In which case you could use:

case 4: // <- this means a short press on the 5th switch MIDI.sendControlChange(52,0,1); // <- this is the command for FS4 on the stomp break;

case 5: // <- this means a short press on the 6th switch MIDI.sendControlChange(53,0,1); // <- this is the command for FS5 on the stomp break;

Does that help?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

stoonoon commented 2 years ago

Hey Stoo! I really appreciate your help with all of this! I had one more question if you had a moment… Would you have the code to add a potentiometer/expression pedal to this code? I appreciate it!

Sorry - that's not something I ever implemented on this version. I did start to add one on my other switcher - https://github.com/stoonoon/hxsMidiSwitchTouch - it was working at one point, but now mine doesn't.... I suspect it's a wiring issue, but never found it useful enough to be too bothered about troubleshooting it.

If you wanted to have a go at implementing it yourself, I think you might be able to get away with pasting in the "byte readPedalPos()" and "void readExpPedalCC()" functions from 07_exp_pedal.ino into your code and then add the "readExpPedalCC();" line from 11_loop.ino into your "void loop()" function

Then you'd also need any relevant variable declarations too - should be either from the top of 08_exp_pedal.ino or from 02_globals.ino

gobbersbubbus commented 2 years ago

You’re insane Stoo, so knowledgeable!

Okay, final question and I stop persevering you. My pot does not flow 0-100%, or 0-127, it goes from 0-100% at about 10%…

In your description I see you have a unique volume pedal and I should be able to “simplify the mapping from R2 to pd1 as they should rise proportionally to each other through the full extent of any travel…”

Would this be just adjusting the buffer value or am I way off?

Again, thank you so much!

On May 25, 2022, at 3:30 AM, Stuart Noon @.***> wrote:

 Hey Stoo! I really appreciate your help with all of this! I had one more question if you had a moment… Would you have the code to add a potentiometer/expression pedal to this code? I appreciate it!

Sorry - that's not something I ever implemented on this version. I did start to add one on my other switcher - https://github.com/stoonoon/hxsMidiSwitchTouch - it was working at one point, but now mine doesn't.... I suspect it's a wiring issue, but never found it useful enough to be too bothered about troubleshooting it.

If you wanted to have a go at implementing it yourself, I think you might be able to get away with pasting in the "byte readPedalPos()" and "void readExpPedalCC()" functions from 07_exp_pedal.ino into your code and then add the "readExpPedalCC();" line from 11_loop.ino into your "void loop()" function

Then you'd also need any relevant variable declarations too - should be either from the top of 08_exp_pedal.ino or from 02_globals.ino

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

stoonoon commented 2 years ago

If you've got a linear pot which sends 0.0V for off/heeldown and 5.0V for on/toedown, then I would try replacing the readPedalPos() function with something like this:

byte readPedalPos() { int raw = analogRead(analogExpressionPedalPin); // get pedal position input (range 0 to 1023) if (raw) { // got some pedal position reading float pdl; pdl = mapf(raw, 0, 1023, 0, 127); // map pedal position into a 0-127 range for MIDI return byte(pdl); } // if(raw) else return 0; // no pedal position reading returned - assume heel down }// byte readPedalPos()

Might need to add some deadzone compensation in later but hopefully that'll be closer to what you need?

gobbersbubbus commented 2 years ago

I will monkey with it, thanks Stoo!!!!

gobbersbubbus commented 1 year ago

Hey Stoo!Question, in your V1 code, is it possible to do a three button press? How would one code that in this?Thank you!On May 25, 2022, at 3:29 PM, Stuart Noon @.***> wrote: If you've got a linear pot which sends 0.0V for off/heeldown and 5.0V for on/toedown, then I would try replacing the readPedalPos() function with something like this: byte readPedalPos() { int raw = analogRead(analogExpressionPedalPin); // get pedal position input (range 0 to 1023) if (raw) { // got some pedal position reading float pdl; pdl = mapf(raw, 0, 1023, 0, 127); // map pedal position into a 0-127 range for MIDI return byte(pdl); } // if(raw) else return 0; // no pedal position reading returned - assume heel down }// byte readPedalPos() Might need to add some deadzone compensation in later but hopefully that'll be closer to what you need?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

stoonoon commented 1 year ago

Hey Stoo!Question, in your V1 code, is it possible to do a three button press? How would one code that in this?Thank you!

I'm honestly not sure. It wasn't something I'd considered at the time, but there is a small chance it just might work. That said - I'd be surprised if it worked reliably....

If you wanted to give it a try, the part that looks for mutiple button presses is in the readButtons() function in hxsMidiSwitcher.ino from line 157

You could try changing the part that goes

else if ( switchPressed[6] && switchPressed[7]) { // last two switches - reset to page 0 and patch 0
        nextCommand = pagePatchReset;
        currentPage = 0;
      }

to

else if ( switchPressed[5] && switchPressed[6] && switchPressed[7]) { // last three switches - reset to page 0 and patch 0
        nextCommand = pagePatchReset;
        currentPage = 0;
      }

and see how you get on. My hunch would be that if you also have 2-button combos set up for any 2 of the buttons in your 3-button combo, then you'd probably get the 2-button combo detected and the 3-button one ignored a lot of the time.

gobbersbubbus commented 1 year ago

Thank you sir! I’ll give it a try!-Preston On Dec 5, 2022, at 6:32 PM, Stuart Noon @.***> wrote:

Hey Stoo!Question, in your V1 code, is it possible to do a three button press? How would one code that in this?Thank you!

I'm honestly not sure. It wasn't something I'd considered at the time, but there is a small chance it just might work. That said - I'd be surprised if it worked reliably.... If you wanted to give it a try, the part that looks for mutiple button presses is in the readButtons() function in hxsMidiSwitcher.ino from line 157 You could try changing the part that goes else if ( switchPressed[6] && switchPressed[7]) { // last two switches - reset to page 0 and patch 0 nextCommand = pagePatchReset; currentPage = 0; }

to else if ( switchPressed[5] && switchPressed[6] && switchPressed[7]) { // last three switches - reset to page 0 and patch 0 nextCommand = pagePatchReset; currentPage = 0; }

and see how you get on. My hunch would be that if you also have 2-button combos set up for any 2 of the buttons in your 3-button combo, then you'd probably get the 2-button combo detected and the 3-button one ignored a lot of the time.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>

gobbersbubbus commented 1 year ago

Hey Stoo!I am trying to add an LED indicator for a tap tempo, do know if there is a way to put that into this code?Thank you!On Dec 6, 2022, at 1:25 @.> wrote:Thank you sir! I’ll give it a try!-Preston On Dec 5, 2022, at 6:32 PM, Stuart Noon @.> wrote:

Hey Stoo!Question, in your V1 code, is it possible to do a three button press? How would one code that in this?Thank you!

I'm honestly not sure. It wasn't something I'd considered at the time, but there is a small chance it just might work. That said - I'd be surprised if it worked reliably.... If you wanted to give it a try, the part that looks for mutiple button presses is in the readButtons() function in hxsMidiSwitcher.ino from line 157 You could try changing the part that goes else if ( switchPressed[6] && switchPressed[7]) { // last two switches - reset to page 0 and patch 0 nextCommand = pagePatchReset; currentPage = 0; }

to else if ( switchPressed[5] && switchPressed[6] && switchPressed[7]) { // last three switches - reset to page 0 and patch 0 nextCommand = pagePatchReset; currentPage = 0; }

and see how you get on. My hunch would be that if you also have 2-button combos set up for any 2 of the buttons in your 3-button combo, then you'd probably get the 2-button combo detected and the 3-button one ignored a lot of the time.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>

stoonoon commented 1 year ago

Hey Stoo!I am trying to add an LED indicator for a tap tempo, do know if there is a way to put that into this code?Thank you!

I guess it might be possible... You'd have to do a bit of research into how many of the last few tap tempo presses that the HX pays attention to... is it just the last 2? Average of the last 4? Does a single tap just set the start time but leave the bpm alone? How long after the last tap would it have to wait before it counts the next tap as the first of a single tap instead of the second of a series of taps? Maybe it's simpler than that, but I don't use it enough to have a feel for it. Either way - you have to work out how to emulate how the HX interprets the taps, and do those same calculations on the taps the switcher is detecting, before sending them on to the HX. It'd take way more time & effort than I'd be willing to throw at it though...

gobbersbubbus commented 1 year ago

Your questions are my questions as well! HahaWell I appreciate your time and understand not tackling it. I’ll see what I can do! Thank you!On May 15, 2023, at 12:36 PM, Stuart Noon @.***> wrote:

Hey Stoo!I am trying to add an LED indicator for a tap tempo, do know if there is a way to put that into this code?Thank you!

I guess it might be possible... You'd have to do a bit of research into how many of the last few tap tempo presses that the HX pays attention to... is it just the last 2? Average of the last 4? Does a single tap just set the start time but leave the bpm alone? How long after the last tap would it have to wait before it counts the next tap as the first of a single tap instead of the second of a series of taps? Maybe it's simpler than that, but I don't use it enough to have a feel for it. Either way - you have to work out how to emulate how the HX interprets the taps, and do those same calculations on the taps the switcher is detecting, before sending them on to the HX. It'd take way more time & effort than I'd be willing to throw at it though...

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>

stoonoon commented 1 year ago

Your questions are my questions as well! HahaWell I appreciate your time and understand not tackling it. I’ll see what I can do! Thank you!On May 15, 2023, at 12:36 PM, Stuart Noon @.***> wrote:

Good luck!

gobbersbubbus commented 7 months ago

Hey Stoo!I had another question about the code. Would it be possible to have a way the switch behave as a toggle? For example, have one push button trigger a control change of 1 sending “velocity” of 127 then the second press send the “velocity” of 0? How would that be implemented in the code?Thank you!-Preston On May 15, 2023, at 12:47 PM, Stuart Noon @.***> wrote:

Your questions are my questions as well! HahaWell I appreciate your time and understand not tackling it. I’ll see what I can do! Thank you!On May 15, 2023, at 12:36 PM, Stuart Noon @.***> wrote:

Good luck!

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>

stoonoon commented 7 months ago

Hey Stoo!I had another question about the code. Would it be possible to have a way the switch behave as a toggle? For example, have one push button trigger a control change of 1 sending “velocity” of 127 then the second press send the “velocity” of 0? How would that be implemented in the code?Thank you!-Preston

The button actions are hard coded according to which page you're on, so this would be an awkward one to do easily without some significant changes.

One possible workaround - if you can make do with only one toggle type button, then you could create two pages that are the same except for button x on the first page has its action in the midiSend function set to CC send with a value of 127 and then also change the menu page to 2.

On menu page 2, the action would need to be reversed so that it sends the CC value as zero and then sets the menu page pack to 1.

stoonoon commented 7 months ago

Hey Stoo!I had another question about the code. Would it be possible to have a way the switch behave as a toggle?

Not sure why I didn't think of this earlier, but there's no need to use multiple pages.

Instead of having something like :

case 0: MIDI.sendControlChange(49,0,1); //FS1 break;

you could have something like:

case 0: static bool switch0NextActionIsA = true; // this will only set the variable to true on the first time the code gets here if (switch0NextActionIsA) { // then we do action "A" for this switch : MIDI.sendControlChange(69,0,1); //snapshot 1 switch0NextActionIsA = false; // use action "B" next time } else { // then we do action "B" for this switch : MIDI.sendControlChange(69,1,1); //snapshot 2 switch0NextActionIsA = true; // use action "A" next time } break;

gobbersbubbus commented 7 months ago

Thanks for the fast response! I’ll throw it in and tinker with it!On Mar 30, 2024, at 9:22 AM, Stuart Noon @.***> wrote:

Hey Stoo!I had another question about the code. Would it be possible to have a way the switch behave as a toggle?

Not sure why I didn't think of this earlier, but there's no need to use multiple pages. Instead of having something like : case 0: MIDI.sendControlChange(49,0,1); //FS1 break; you could have something like: case 0: static bool switch0NextActionIsA = true; // this will only set the variable to true on the first time the code gets here if (switch0NextActionIsA) { // then we do action "A" for this switch : MIDI.sendControlChange(69,0,1); //snapshot 1 switch0NextActionIsA = false; // use action "B" next time } else { // then we do action "B" for this switch : MIDI.sendControlChange(69,1,1); //snapshot 2 switch0NextActionIsA = true; // use action "A" next time } break;

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you modified the open/close state.Message ID: @.***>