コード例 #1
0
ファイル: Client.cs プロジェクト: dada/theresa
 private void OpenDevice(int id)
 {
     byte[] o = new byte[2] { 111, Convert.ToByte(id) };
       _Net.Write(o, 0, 2);
       _Net.Flush();
       _CurrentDevice = Devices[id];
 }
コード例 #2
0
ファイル: Client.cs プロジェクト: dada/theresa
 private void GetDevices()
 {
     _Net.Write(new byte[2] { 63, 35 }, 0, 2);
       _Net.Flush();
       byte[] n = new byte[1] { 0 };
       while(!_Net.DataAvailable) {
     Thread.Sleep(10);
       }
       if(_Net.Read(n, 0, 1) != 0) {
     int ndevices = Convert.ToInt32(n[0]);
     _Devices = new MidiDevice[ndevices];
     for(int i = 0; i < ndevices; i++) {
       _Net.Write(new byte[3] { 63, 110, Convert.ToByte(i) }, 0, 3);
       _Net.Flush();
       while(!_Net.DataAvailable) {
     Thread.Sleep(10);
       }
       byte[] namebuf = new byte[32];
       if(_Net.Read(namebuf, 0, 32) != 0) {
     string name = String.Empty;
     for(int j = 0; j < 32; j++) {
       name += Convert.ToChar(namebuf[j]);
     }
     Devices[i] = new MidiDevice();
     Devices[i].ID = i;
     Devices[i].Name = name;
       }
       else {
     Console.WriteLine("could not read!");
       }
     }
     // Devices.Items.Clear();
     // foreach(object dev in devices) {
     //   Devices.Items.Add(dev);
     // }
       } else {
     Console.WriteLine("could not read!");
       }
 }
コード例 #3
0
ファイル: Client.cs プロジェクト: dada/theresa
        public Client()
        {
            Assembly me = Assembly.GetExecutingAssembly();

              if(System.Environment.OSVersion.Platform != PlatformID.WinCE) {
            Width = 240;
            Height = 320 + 34;
              } else {
            this.WindowState = FormWindowState.Maximized;
            this.FormBorderStyle = FormBorderStyle.None;
            this.ControlBox = false;
            this.Menu = null;
              }

              _MagentaKiller = new ImageAttributes();
              _MagentaKiller.SetColorKey(Color.Magenta, Color.Magenta);

              _CurrentConnection = new ConnectionDetails();
              _CurrentConnection.UseActiveSync = true;

              // load default skin
              _DefaultSkin = new Skin();
              _DefaultSkin.Load("Default");

              // reload last settings
              string layout = "Default";
              string skin = "Default";
              _LastDeviceUsed = 0;
              if(File.Exists(AppPath + "\\Last.xml")) {
            StreamReader file = new StreamReader(AppPath + "\\Last.xml");
            string xml = file.ReadToEnd();
            file.Close();
            XmlDocument x = new XmlDocument();
            x.LoadXml(xml);
            foreach(XmlNode n in x.ChildNodes[0].ChildNodes) {
              if(n.NodeType == XmlNodeType.Element) {
            switch(n.Name) {
            case "Connection":
              _CurrentConnection.UseActiveSync = Convert.ToBoolean(n.Attributes["activesync"].Value);
              _CurrentConnection.Host = n.Attributes["host"].Value;
              _CurrentConnection.Port = Convert.ToInt32(n.Attributes["port"].Value);
              break;
            case "Layout":
              layout = n.Attributes["name"].Value;
              break;
            case "Skin":
              skin = n.Attributes["name"].Value;
              break;
            case "Device":
              _LastDeviceUsed = Convert.ToInt32(n.Attributes["id"].Value);
              break;
            }
              }
            }
              }

              CurrentSkin = new Skin();
              CurrentSkin.Load(skin, _DefaultSkin);

              this.BackColor = CurrentSkin.BackgroundColor;
              this.Text = String.Format("Theresa v{0}.{1}.{2}",
            me.GetName().Version.Major,
            me.GetName().Version.Minor,
            me.GetName().Version.Build
              );
              if(me.GetManifestResourceStream("Theresa.Mae.ico") != null) {
            this.Icon = new Icon(me.GetManifestResourceStream("Theresa.Mae.ico"));
              }

              if(me.GetManifestResourceStream("Theresa.Logo.png") != null) {
            _LogoBitmap = new Bitmap(me.GetManifestResourceStream("Theresa.Logo.png"));
              } else {
            _LogoBitmap = new Bitmap(87, 25);
              }
              _Logo = new Control();
              _Logo.BackColor = CurrentSkin.BackgroundColor;
              _Logo.Bounds = new Rectangle(0, 0, _LogoBitmap.Size.Width, _LogoBitmap.Size.Height);
              _Logo.Paint += new PaintEventHandler(PaintLogo);
              _Logo.Parent = this;

              _Quit = new BigButton(CurrentSkin);
              if(me.GetManifestResourceStream("Theresa.Button-Quit.png") != null) {
            _Quit.Picture = new Bitmap(me.GetManifestResourceStream("Theresa.Button-Quit.png"));
              }
              _Quit.BackColor = Color.DarkRed;
              _Quit.Bounds = new Rectangle(this.ClientSize.Width-25, 0, 24, 24);
              _Quit.Text = "Q";
              _Quit.Click += new EventHandler(OnQuit);
              _Quit.Parent = this;

              _Settings = new BigButton(CurrentSkin);
              if(me.GetManifestResourceStream("Theresa.Button-Configure.png") != null) {
            _Settings.Picture = new Bitmap(me.GetManifestResourceStream("Theresa.Button-Configure.png"));
              }
              _Settings.Bounds = new Rectangle(this.ClientSize.Width-50, 0, 24, 24);
              _Settings.Text = "C";
              _Settings.Click += new EventHandler(OnSettings);
              _Settings.Parent = this;

              _DisplayMode = new BigButton(CurrentSkin);
              if(me.GetManifestResourceStream("Theresa.Button-DisplayMode.png") != null) {
            _DisplayMode.Picture = new Bitmap(me.GetManifestResourceStream("Theresa.Button-DisplayMode.png"));
              }
              _DisplayMode.Bounds = new Rectangle(this.ClientSize.Width-75, 0, 24, 24);
              _DisplayMode.Text = "#";
              _DisplayMode.Click += new EventHandler(OnChangeDisplayMode);
              _DisplayMode.Parent = this;

              _SavePreset = new BigButton(CurrentSkin);
              if(me.GetManifestResourceStream("Theresa.Button-Save.png") != null) {
            _SavePreset.Picture = new Bitmap(me.GetManifestResourceStream("Theresa.Button-Save.png"));
              }
              _SavePreset.Bounds = new Rectangle(this.ClientSize.Width-100, 0, 24, 24);
              _SavePreset.Text = "S";
              _SavePreset.Click += new EventHandler(OnSavePreset);
              _SavePreset.Parent = this;

              _LoadPreset = new BigButton(CurrentSkin);
              if(me.GetManifestResourceStream("Theresa.Button-Quit.png") != null) {
            _LoadPreset.Picture = new Bitmap(me.GetManifestResourceStream("Theresa.Button-Load.png"));
              }
              _LoadPreset.Bounds = new Rectangle(this.ClientSize.Width-125, 0, 24, 24);
              _LoadPreset.Text = "L";
              _LoadPreset.Click += new EventHandler(OnLoadPreset);
              _LoadPreset.Parent = this;

              _TryToConnect = new System.Windows.Forms.Timer();
              _TryToConnect.Tick += new EventHandler(OnTryToConnect);
              _TryToConnect.Interval = 1000;
              _TryToConnect.Enabled = false;

              LoadLayout(layout);
              Connect();

              if(_Connected) {
            CurrentDevice = Devices[_LastDeviceUsed];
              } else {
            _Devices = new MidiDevice[0];
            _CurrentDevice = new MidiDevice();
            _CurrentDevice.ID = 0;
            _CurrentDevice.Name = "none";
            Console.WriteLine("Can't connect");
            // _TryToConnect.Enabled = true;
              }
        }
コード例 #4
0
ファイル: Client.cs プロジェクト: dada/theresa
 private void Connect()
 {
     _Client = new TcpClient();
       string host;
       int port;
       if(_CurrentConnection.UseActiveSync) {
     if(System.Environment.OSVersion.Platform == PlatformID.WinCE) {
       host = "PPP_PEER";
       port = 7353;
     } else {
       host = "localhost";
       port = 7353;
     }
       } else {
     host = _CurrentConnection.Host;
     port = _CurrentConnection.Port;
       }
       try {
     _Client.Connect(host, port);
     _Client.NoDelay = true;
     _Connected = true;
       }
       catch(SocketException ex) {
     Console.WriteLine("got exception: " + ex.ToString());
     // MessageBox.Show( "got exception: " + ex.ToString() + "\nMessage: " + ex.Message + "\nSocket Error Code: " + ex.ErrorCode.ToString() );
       }
       if(_Connected) {
     _Net = _Client.GetStream();
     GetDevices();
     if(_CurrentDevice != null && _CurrentDevice.Name == "none") {
       if(_LastDeviceUsed > _Devices.Length - 1) {
     OpenDevice(0);
       } else {
     OpenDevice(_LastDeviceUsed);
       }
     }
     // _TryToConnect.Enabled = false;
       } else {
     _Devices = new MidiDevice[0];
     _CurrentDevice = new MidiDevice();
     _CurrentDevice.ID = 0;
     _CurrentDevice.Name = "none";
       }
 }