public PlaybackEvent(object source, PlaybackAction action, Sound sound) : base(source, PlaybackEvent.stringify(action, sound)) { this._action = action; this._sound = sound; }
private static string stringify(PlaybackAction action, Sound sound) { return action.ToString() + " " + sound.ToString(); }
public ResumeEvent(object source, Sound sound) : base(source, PlaybackEvent.PlaybackAction.RESUME, sound) { }
public LoopEvent(object source, Sound sound) : base(source, PlaybackEvent.PlaybackAction.LOOP, sound) { }
//Drag&Drop Handling private void Element_MouseMove(object sender, MouseEventArgs e) { int x = e.X; int y = e.Y; Control source = (Control)sender; while (!(source is MainFrame)) { x += source.Location.X; y += source.Location.Y; source = source.Parent; } if (((Control)sender) is ListBox && _draggedElement == null && _mouseDown && soundLibrary1.SelectedSound != null)//if drag from the library =>display sound and move it { this._selectedSound = this.soundLibrary1.SelectedSound; _draggedElement = new Label() { BackColor = Color.Gray, Text = _selectedSound.Name, Location = this._mouseLocation };//add the listeners to record mouvements _draggedElement.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Element_MouseUp);// at the end of drag&drop this.Controls.Add(_draggedElement); this.Controls.SetChildIndex(_draggedElement, 0); } if (_draggedElement != null) { //just an update of the mouse position this._mouseLocation.X = x; this._mouseLocation.Y = y; _draggedElement.Location = _mouseLocation; } }
public void AddSound(Sound s) { this._soundLibrary.AddSound(s); this.Save(); }
public LibraryEvent(object source, LibraryAction action, Sound s) : base(source, action.ToString()) { this._action = action; this._sound = s; }
//end of drag&drop private void Element_MouseUp(object sender, MouseEventArgs e) { Point m = _mouseLocation; Point p; foreach (Control c in this.Controls) { p = c.Location; if (c is PadView && _selectedSound != null && m.X > p.X && m.Y > p.Y && m.X < p.X + c.Height && m.Y < p.Y + c.Width) //check if mouse is over a pad { ((TwoStateButton.TwoStateButton)c).Data = _selectedSound.ID; } } p = this.timeLine1.Location; if (_selectedSound != null && m.X > p.X && m.Y > p.Y && m.X < p.X + timeLine1.Width && m.Y < p.Y + timeLine1.Height) //check if mouse is over the timeLine { this.timeLine1.pnlTrack_draggSoundIn(_selectedSound,m.X -p.X, m.Y-p.Y);//delegate handling to the sequencer with coordinates within the sequencer this._selectedSound = null; } this.Controls.Remove(_draggedElement); //after mouseUp , reset selected event this._mouseDown = false; this._draggedElement = null; this._selectedSound = null; }
//Reception d'un fichier private void receiveFile(string[] words, Client client) { ServerMainFrame.GetInstance().addLog(client.Id + "-" + client.Name + " receiving file : " + words[2]); int BufferSize = 1000; byte[] RecData = new byte[BufferSize]; int RecBytes; NetworkStream netstream = null; try { netstream = new NetworkStream(client.Socket); string folderPath = ConfigurationManager.AppSettings["SamplesPath"]; bool isExists = System.IO.Directory.Exists(folderPath); if (!isExists) System.IO.Directory.CreateDirectory(folderPath); words[2] = words[2].Substring(words[2].LastIndexOf("\\") + 1); int fileNonOverrideIndex = 0; string[] fileNameSplitted = words[2].Split(new char[] { '.' }); string saveFileName = folderPath + "\\" + words[2]; while (System.IO.File.Exists(saveFileName)) { fileNonOverrideIndex++; saveFileName = folderPath + "\\"; for (int i = 0; i < fileNameSplitted.Length - 1; i++) { saveFileName += fileNameSplitted[i]; } saveFileName += "(" + fileNonOverrideIndex + ")." + fileNameSplitted[fileNameSplitted.Length - 1]; } if (saveFileName != string.Empty) { int totalrecbytes = 0; FileStream Fs = new FileStream(saveFileName, FileMode.OpenOrCreate, FileAccess.Write); bool stop = false; while ((RecBytes = netstream.Read(RecData, 0, RecData.Length)) > 4 && !stop) { Fs.Write(RecData, 0, RecBytes); totalrecbytes += RecBytes; stop = RecBytes < 999; } Console.WriteLine(totalrecbytes); Fs.Close(); } netstream.Close(); Sound newSound = new RTS.Model.Sound(words[1], words[2], saveFileName, new byte[1]); if (Math.Abs(newSound.FileSize - long.Parse(words[3])) < 250) { ServerSoundLibrary.GetInstance().AddSound(newSound); ServerMainFrame.GetInstance().addLog(client.Id + "-" + client.Name + " file received : " + words[2]); } else { System.IO.File.Delete(saveFileName); ServerMainFrame.GetInstance().addLog(client.Id + "-" + client.Name + " error on file size : " + words[2] + " (orig : " + words[3] + ",received :" + newSound.FileSize + ")"); } client.GetNextServerSideNeededSample(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public PlayEvent(object source, Sound sound) : base(source, PlaybackEvent.PlaybackAction.PLAY, sound) { }
public EndEvent(object source, Sound s) : base(source, PlaybackAction.END, s) { }
//Permet d'attendre que le client soit prêt et de rééssayer régulièrement private void PendingSendSound(Sound sound) { while (this._watch.IsRunning) { if (this._watch.ElapsedMilliseconds > 3000)//Si le client n'a pas répondu dans les 3sec, on renvoit l'instruction { this._sending = false; this.SendSound(sound); break; } } }
//Send a sound to the client public bool SendSound(Sound sound) { if (!_sending) { try { ServerMainFrame.GetInstance().addLog("Try to send " + sound.Name + " to " + this.Name); NetworkStream netstream = new NetworkStream(this._soc); StreamWriter sw = new StreamWriter(netstream); sw.AutoFlush = true; sw.WriteLine(NetworkParser.getCode(NetworkParser.Operation.GIVE_FILE) + ";" + sound.ID + ";" + sound.Name + ";" + sound.FileSize);//envoie du nom et id du fichier (et la taille pour comparaison) this._sending = true; this._watch = new Stopwatch();//Création d'une stopwatch pour réenvoyer l'instruction au bout de 3sec si pas de réponse (client busy) this._watch.Start(); this.PendingSendSound(sound); } catch (Exception e) { Console.WriteLine("Exception in Sound sending : " + e); } } return true; }
public PauseEvent(object source, Sound sound) : base(source, PlaybackEvent.PlaybackAction.PAUSE, sound) { }
private void Validate(object sender, EventArgs e) { this._sound = (Sound)this.SoundLibrary.Items[this.SoundLibrary.SelectedIndex]; this.Close(); }