BBWIWARG.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Threading;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Net;
  8. using bbiwarg.Output.DebugOutput;
  9. using bbiwarg.Input.InputProviding;
  10. using bbiwarg.Input.InputHandling;
  11. using bbiwarg.TUIO;
  12. namespace bbiwarg
  13. {
  14. class BBIWARG
  15. {
  16. InputProvider inputProvider;
  17. InputHandler inputHandler;
  18. TuioCommunicator tuioCommunicator;
  19. DebugWindow debugWindow;
  20. Thread debugOutputThread;
  21. static void Main(string[] args)
  22. {
  23. Console.SetWindowSize(Parameters.ConsoleWidth, Parameters.ConsoleHeight);
  24. handleArgs(args);
  25. BBIWARG program = new BBIWARG();
  26. program.run();
  27. }
  28. public BBIWARG()
  29. {
  30. // inputProvider
  31. createInputProvider();
  32. inputProvider.DeviceStartedEvent += handleDeviceStartedEvent;
  33. // inputHandler
  34. inputHandler = new InputHandler();
  35. inputProvider.NewFrameEvent += inputHandler.handleNewFrame;
  36. // tuioCommunicator
  37. if (Parameters.TuioEnabled)
  38. {
  39. tuioCommunicator = new TuioCommunicator(Parameters.TuioIP.ToString(), Parameters.TuioPort);
  40. inputHandler.NewProcessedFrameEvent += tuioCommunicator.handleNewFrameData;
  41. }
  42. // debug output
  43. if (Parameters.DebugOutputEnabled)
  44. {
  45. debugOutputThread = new Thread(new ThreadStart(debugOutputThreadStart));
  46. }
  47. }
  48. public void run()
  49. {
  50. inputProvider.start();
  51. }
  52. private void createInputProvider()
  53. {
  54. if (Parameters.InputSource == InputType.Movie)
  55. inputProvider = new VideoInputProvider(Parameters.InputMoviePath);
  56. else
  57. inputProvider = new InputProvider();
  58. }
  59. private void debugOutputThreadStart()
  60. {
  61. debugWindow = new DebugWindow(inputProvider, inputHandler);
  62. debugWindow.Run(Parameters.DebugOutputUpdateRate, Parameters.DebugOutputRenderRate);
  63. }
  64. private void handleDeviceStartedEvent(object sender, EventArgs e)
  65. {
  66. startOutputThreads();
  67. }
  68. private void startOutputThreads()
  69. {
  70. if (Parameters.DebugOutputEnabled)
  71. debugOutputThread.Start();
  72. }
  73. private static void handleArgs(String[] args)
  74. {
  75. if (args.Length > 0)
  76. {
  77. IPAddress ipAddress;
  78. Int16 port;
  79. String ipString = null;
  80. String portString = null;
  81. if (args.Length == 2)
  82. {
  83. ipString = args[0];
  84. portString = args[1];
  85. }
  86. else if (args.Length == 1)
  87. {
  88. String[] parts = args[0].Split(':');
  89. ipString = parts[0];
  90. if (parts.Length == 2)
  91. portString = parts[1];
  92. }
  93. while (!TuioCommunicator.tryParseIPAddress(ipString, out ipAddress))
  94. {
  95. Console.WriteLine("Please insert the TUIO-Client's IP (Default is 127.0.0.1):");
  96. ipString = Console.ReadLine();
  97. }
  98. Console.WriteLine("TUIO-IP is set to:" + Parameters.TuioIP.ToString());
  99. while (!TuioCommunicator.tryParsePort(portString, out port))
  100. {
  101. Console.WriteLine("Please insert the TUIO-Client's Port (Default is 3333):");
  102. portString = Console.ReadLine();
  103. }
  104. Console.WriteLine("TUIO-PORT is set to:" + Parameters.TuioPort);
  105. Parameters.setTuioParameters(true, ipAddress, port);
  106. }
  107. }
  108. }
  109. }