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 p5live-midi.js #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update p5live-midi.js #105

wants to merge 1 commit into from

Conversation

kaosbeat
Copy link

This seems to works for me for adding extra mididevices to the show. Need to do some extended testing, but in short,. I needed to connect multiple midi devices, anmd this way, I can give setupMidi a midiobjectname. Not sure if this is the best iomplementation, but it seems to work and it should not break existing code.

still testing

	// setup MIDI in/out by ID # or "name" (see console.log)
	setupMidi(1, 0, false, "miditest") // in, out, globalvars = false, name is miditest


	// set custom functions and custom device name
	miditest.noteOn = (note) => {   
		// print(note)
		fill(note.velocity)
		noStroke()
			circle(random(width), random(height), note.number * note.octave)
	}

This seems to works for me for adding extra mididevices to the show. Need to do some extended testing, but in short,. I needed to connect multiple midi devices, anmd this way, I can give setupMidi  a midiobjectname.
Not sure if this is the best iomplementation, but it seems to work and it should not break existing code.

_still testing_
@kaosbeat
Copy link
Author

test look fine, but it might complicate the API a bit? Although everything works as intended (and as it used to, with the midi5 object) if you do not add the extra parameter

@ffd8
Copy link
Owner

ffd8 commented Nov 29, 2024

Heyhey - cool idea, so it's not locked down to a single variable/scope – i need to test a bit before merging. i did a quicko update release yesterday to include the latest p5.js + some bugs within the demos file that got messed up during a data-loss.. so can plan for it in the next version.

In general, curious what your midi setup is that you needed multiple instances? I guess having multiple separate gears plugged in on their own midi port, rather than chained and using diff channels? I haven't tested much outside of a single gear, so mostly made sure channels/notes/control-changes worked (testing with a midi keyboard + elektron model:cycles).

@kaosbeat
Copy link
Author

kaosbeat commented Nov 29, 2024

you would not want to see a screenshot of my connected mididevices :-) It comes and goes... but mostly I have mappings ready for separate devices, If I can attach them to a separate object, I can quickly swap controls in software. Using mainly selfbuilt hardware, it gets messy real quick. I adhere no standard mapping, I adapt to the device

Example this one is for a more standard device I have (OG OP-1) , adapted to use the above patch. (it still uses some global vars and I still merged it with another controller (tidal) here so might not be the cleanest code, but you get the idea)

function initMidi(p5, midiobject){
   midiobject.controlChange = (cc) => {
   	let index = cc.number;
   	let value = cc.value;
   	value = value/127;
   	if (cc.channel == 1){  //reserve channel 0(tidal) or 1(p5live) for tidalcontroller & OP1
   		switch (index) {
   			case 1:  // blue knob
   				pfvars.p1 = value
   				break; 
   			
   			case 2:  // green knob
   				pfvars.p2 = value
   				break; 
   			
   			case 3:  //white knob
   				pfvars.p3 = value
   				break; 
   			
   			case 4:  //orange knob
   				pfvars.p4 = value
   				break; 
   			

   			case 5: break; // help mode (blue button)
   			case 6: break; // metronome mode (blue button)

   			case 7: 
   				changeSubCollection("curated")
   				break; // synth mode (blue button)
   			case 8: 
   				changeSubCollection("TImg")
   				break; // drum mode (green button)
   			case 9: 
   				changeSubCollection("GIDImg")
   				break; // tape mode (orange button)
   			case 10: break; // mix mode 

   			case 11:  // tape channel 1  						
   				if (value == 1) {// imageonly(); 
   					if (pfvars.s0) { pfvars.s0 = false} 
   					else { pfvars.s0 = true;  }
   					loginfo("image layer " + pfvars.s0)
   				} 
   				break; 
   			case 12:  // tape channel 2
   				if (value == 1) {
   					if (pfvars.s1) { pfvars.s1 = false} 
   					else { pfvars.s1 = true; }
   					loginfo("adding 3D visuals" + pfvars.s1) 
   				}
   				break;
   			case 13: // tape channel 3
   				if (value == 1) {
   				// P5only(); 
   					if (pfvars.s2) { pfvars.s2 = false} 
   					else { pfvars.s2 = true; }
   					loginfo("adding data visuals" + pfvars.s2)
   				}
   				break;
   			case 14: // tape channel 4
   				if (value == 1) {
   					// dataonly(); 
   					if (pfvars.s3) { pfvars.s3 = false;  } 
   					else { pfvars.s3 = true;  }
   					loginfo("adding data layer" + pfvars.s2 )
   				}
   				break;

   			case 15:  
   				if (value == 1) {
   					loadNextArtist()
   				}
   				break; // lift  (orange arrow up button)
   			case 16: 
   				if (value == 1) {
   					loadPrevArtist()
   				}
   				break; // drop  (orange arrow down button)
   			case 17: break; //  cut  (orange scissors)

   			case 50: break;  // preset 1
   			case 51: break;  // preset 2
   			case 52: break;  // preset 3
   			case 21: break;  // preset 4
   			case 22: break;  // preset 5
   			case 23: break;  // preset 6
   			case 24: break;  // preset 7
   			case 25: break;  // preset 8

   			// right button group
   			case 26: break;  // preset arp mode
   			case 49: break;  // preset com mode
   			case 48: break;  // preset rec mode button (orange mic)

   			case 38: break; // rec button (orange circle button)
   			case 39: break; // play button
   			case 40: break; // stop button

   			/// END OF OP1 CONTROLLER VALUES
   			
   			/// start of tidal controller values

   			case 64: { p5.viewportconf.rotX = value ;break;}
               case 65: { p5.viewportconf.rotY = value ;break;}
               case 66: { p5.viewportconf.rotZ = value ;break;}
               case 67: { p5.viewportconf.rotSpeedX = value*0.001;break;}
               case 68: { p5.viewportconf.rotSpeedY = value*0.001;break;}
               case 69: { p5.viewportconf.rotSpeedZ = value*0.001;break;}
               case 70: { p5.viewportconf.offX = value ;break;}
               case 71: { p5.viewportconf.offY = value ;break;}
               case 72: { p5.viewportconf.offZ = value ;break;}
               case 73: { p5.viewportconf.offSpeedX = value*0.001;break;}
               case 74: { p5.viewportconf.offSpeedY = value*0.001;break;}
               case 75: { p5.viewportconf.offSpeedZ = value*0.001;break;}
               case 76: { 
                   if (value == 0) { 
                       p5.viewportconf.cammode = "fixed"
                   } else if (value == 1) { 
                       p5.viewportconf.cammode = "orbit"
                   } else if (value == 2) { 
                       p5.viewportconf.cammode = "bigorbit"
                   } 
                   break;
               }
               case 77: {p5.viewportconf.audioCutoff = value*10, a.setCutoff(p5.viewportconf.audioCutoff); break; }
               case 78: {p5.viewportconf.audioScale = value*10, a.setScale(p5.viewportconf.audioScale); break; }  

               
               case 119: {  ///hydramode  ///needs refactor according to hydrafunctions.js /// CC > 120 are not passed to P5LIVE
   				let fx = (value*127)%(fxpipe.length)
   				loginfo("setting hydramode " + fxpipe[fx].name)
   				fxpipe[fx]()
   				break;
   			}
   		}
   	}

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.

2 participants