7_idraw_connection.scd 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. (
  2. // Function to test iDraw OSC connection
  3. ~testiDrawConnection = {
  4. var interfaces, ip;
  5. // Log local IP and port information
  6. "SuperCollider OSC server info for iDraw OSC connection:".postln;
  7. "Hostname: %".format(Platform.myHostName).postln;
  8. "Local IP addresses:".postln;
  9. try {
  10. interfaces = "ifconfig".unixCmdGetStdOutLines;
  11. interfaces.do { |line|
  12. if(line.containsi("inet ") && line.containsStringAt(0, "inet").not, {
  13. line = line.replace("\t", "").replace(" ", "");
  14. ip = line.findRegexp("inet([0-9.]+)")[1][1];
  15. " %".format(ip).postln;
  16. });
  17. };
  18. } { |err|
  19. "Could not detect network interfaces: %".format(err).postln;
  20. };
  21. // Alternate way to find IP addresses that might work better on some systems
  22. "Alternative method to find IP addresses:".postln;
  23. try {
  24. thisProcess.platform.getNetworkNameList.do { |netname|
  25. var addr = netname.findRegexp("\\d+\\.\\d+\\.\\d+\\.\\d+");
  26. if(addr.size > 0, {
  27. " %".format(addr[0][1]).postln;
  28. });
  29. };
  30. } { |err|
  31. "Could not use network name list method: %".format(err).postln;
  32. };
  33. "OSC Port: 57120".postln;
  34. "".postln;
  35. "To connect from iDraw OSC:".postln;
  36. "1. Ensure iPad/iPhone is on the same WiFi network".postln;
  37. "2. Open iDraw OSC app".postln;
  38. "3. Set the host/IP to one of the above addresses".postln;
  39. "4. Set the port to 57120".postln;
  40. "5. Ensure iDraw OSC is sending messages with these addresses:".postln;
  41. " - /touch (x, y, pressure)".postln;
  42. " - /pen (pen type)".postln;
  43. " - /color (r, g, b)".postln;
  44. };
  45. // Function to simulate iDraw OSC messages for testing
  46. ~simulateiDrawTouch = { |duration=10|
  47. var endTime, penTypes, penType, r, g, b;
  48. endTime = SystemClock.seconds + duration;
  49. "Simulating iDraw OSC touch events for % seconds".format(duration).postln;
  50. // Start the effects chain if needed
  51. if(~effectsChain.isNil, { ~startEffectsChain.value; });
  52. // First set a pen type
  53. penTypes = [\pen, \monoline, \marker, \pencil, \crayon, \fountainPen, \waterColor];
  54. penType = penTypes.choose;
  55. OSCdef(\penTypeOSC).value(['/pen', penType], nil, nil, nil);
  56. // Set a random color
  57. r = 1.0.rand;
  58. g = 1.0.rand;
  59. b = 1.0.rand;
  60. OSCdef(\colorOSC).value(['/color', r, g, b], nil, nil, nil);
  61. // Generate simulated touch events
  62. fork {
  63. while { SystemClock.seconds < endTime } {
  64. var x = (-0.5 + 1.0.rand);
  65. var y = (-0.5 + 1.0.rand);
  66. var pressure = 1 + 7.rand;
  67. // Send touch message
  68. OSCdef(\touchOSC).value(['/touch', x, y, pressure], nil, nil, nil);
  69. // Wait random time between touch events
  70. rrand(0.1, 0.3).wait;
  71. // Occasionally change pen type or color
  72. if(0.1.coin, {
  73. penType = penTypes.choose;
  74. OSCdef(\penTypeOSC).value(['/pen', penType], nil, nil, nil);
  75. "Changed to pen type: %".format(penType).postln;
  76. });
  77. if(0.1.coin, {
  78. r = 1.0.rand;
  79. g = 1.0.rand;
  80. b = 1.0.rand;
  81. OSCdef(\colorOSC).value(['/color', r, g, b], nil, nil, nil);
  82. "Changed to color: % % %".format(r, g, b).postln;
  83. });
  84. };
  85. "iDraw OSC simulation complete".postln;
  86. };
  87. };
  88. // Run these functions directly
  89. "iDraw OSC connection test functions loaded.".postln;
  90. "To test connection info, run: ~testiDrawConnection.value".postln;
  91. "To simulate iDraw OSC events, run: ~simulateiDrawTouch.value(20)".postln;
  92. )