7_mobile_connection.s 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (
  2. // Function to test mobile connection
  3. ~testMobileConnection = {
  4. // Log local IP and port information
  5. "SuperCollider OSC server info:".postln;
  6. "Hostname: %".format(Platform.myHostName).postln;
  7. "Local IP addresses:".postln;
  8. try {
  9. var interfaces = "ifconfig".unixCmdGetStdOutLines;
  10. interfaces.do { |line|
  11. if(line.containsi("inet ") && line.containsStringAt(0, "inet").not, {
  12. line = line.replace("\t", "").replace(" ", "");
  13. var ip = line.findRegexp("inet([0-9.]+)")[1][1];
  14. " %".format(ip).postln;
  15. });
  16. };
  17. } { |err|
  18. "Could not detect network interfaces: %".format(err).postln;
  19. };
  20. "OSC Port: 57120".postln;
  21. "".postln;
  22. "To connect from a mobile device:".postln;
  23. "1. Ensure mobile device is on the same WiFi network".postln;
  24. "2. Use one of the IP addresses above in your mobile OSC app".postln;
  25. "3. Set the port to 57120".postln;
  26. };
  27. // Function to simulate mobile touch for testing without a mobile device
  28. ~simulateMobileTouch = { |duration=10|
  29. var endTime = SystemClock.seconds + duration;
  30. var touchId = 1000;
  31. "Simulating mobile touch events for % seconds".format(duration).postln;
  32. // Start the effects chain if needed
  33. if(~effectsChain.isNil, { ~startEffectsChain.value; });
  34. // Generate simulated touch events
  35. fork {
  36. while { SystemClock.seconds < endTime } {
  37. var x = 1.0.rand;
  38. var y = 1.0.rand;
  39. var pressure = 0.3 + 0.7.rand;
  40. var state = [\began, \moved, \ended].choose;
  41. // Create realistic touch sequences
  42. if(state == \began, {
  43. touchId = touchId + 1;
  44. OSCdef(\touchOSC).value(['/touch', touchId, x, y, \began, pressure], nil, nil, nil);
  45. // Simulate some movement for this touch
  46. fork {
  47. var moveCount = rrand(3, 8);
  48. moveCount.do {
  49. 0.1.wait;
  50. // Slight movement from original position
  51. x = (x + 0.1.rand2).clip(0, 1);
  52. y = (y + 0.1.rand2).clip(0, 1);
  53. OSCdef(\touchOSC).value(['/touch', touchId, x, y, \moved, pressure], nil, nil, nil);
  54. };
  55. // End the touch
  56. 0.2.wait;
  57. OSCdef(\touchOSC).value(['/touch', touchId, x, y, \ended, pressure], nil, nil, nil);
  58. };
  59. });
  60. // Wait random time between new touch events
  61. rrand(0.2, 1.0).wait;
  62. };
  63. "Mobile touch simulation complete".postln;
  64. };
  65. };
  66. // Run these functions directly
  67. "Mobile connection test functions loaded.".postln;
  68. "To test connection info, run: ~testMobileConnection.value".postln;
  69. "To simulate mobile touch events, run: ~simulateMobileTouch.value(20)".postln;
  70. )