/* Copyright (C) Arnaud Houdelette 2012-2014 Copyright (C) Emmanuel Langlois 2012-2014 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ using System; using System.Collections.Generic; using Gtk; namespace DMX2 { //TODO : Changement de nom [System.ComponentModel.ToolboxItem(true)] public partial class SeqSonUI : SequenceurUI { ListStore lsFiles = null; SequenceurSon sequenceur; public bool updateflag=true; bool ff=false; bool rw=false; public void buildListFiles () { lsFiles = new ListStore(typeof(string)); listFiles.EnableGridLines= TreeViewGridLines.Both; var idCol = new Gtk.TreeViewColumn (); var idCell = new Gtk.CellRendererText (); idCol.Title = "N°"; idCol.PackStart (idCell, true); idCol.SetCellDataFunc (idCell, new Gtk.TreeCellDataFunc (RenderNum)); listFiles.AppendColumn (idCol); var fileCol = new Gtk.TreeViewColumn (); var fileCell = new Gtk.CellRendererText (); fileCol.Title = "Nom"; fileCol.PackStart (fileCell, true); fileCol.SetCellDataFunc (fileCell, new Gtk.TreeCellDataFunc (RenderFile)); listFiles.AppendColumn (fileCol); listFiles.Model = lsFiles; } void UpdListFiles () { lsFiles.Clear(); foreach (var file in sequenceur.Files) { lsFiles.AppendValues(file); } } void RenderNum (TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) { if (Conduite.Courante==null) return; string num=string.Empty; string l = tree_model.GetValue (iter, 0) as string; if( sequenceur.CurFile == l ) num+= "->"; (cell as Gtk.CellRendererText).Text = num + (sequenceur.Files.IndexOf(l)+1).ToString(); } void RenderFile (TreeViewColumn tree_column, CellRenderer cell, TreeModel tree_model, TreeIter iter) { if (Conduite.Courante==null) return; string l = tree_model.GetValue (iter, 0) as string; (cell as Gtk.CellRendererText).Text = l; } public SeqSonUI (SequenceurSon s):base(s) { this.Build (); sequenceur = s; buildListFiles(); } #region implemented abstract members of DMX2.SequenceurUI public override void Update (bool full) { if (full||updateflag ) { listFiles.QueueDraw(); SelectionneLigne(); UpdListFiles(); } updateflag=false; sclVolume.Value = sequenceur.Volume; posLabel.Text = string.Format("n°{0}",sequenceur.Index+1); TimeSpan dur = sequenceur.Duration; TimeSpan cur = sequenceur.PlayTime; if (ff) sequenceur.PlayTime += TimeSpan.FromSeconds(1); if (rw) sequenceur.PlayTime += TimeSpan.FromSeconds(-1); timeLabel.LabelProp = string.Format ("elap.{0:mm\\:ss\\.fff}\nrem. {1:mm\\:ss\\.fff}",cur,dur-cur); pbCur.Fraction = (dur == TimeSpan.Zero)?0:(cur.TotalMilliseconds/dur.TotalMilliseconds); } int IndexSelection() { var sel = listFiles.Selection.GetSelectedRows(); if(sel.Length ==0) return -1; return listFiles.Selection.GetSelectedRows()[0].Indices[0]; } protected void OnActAddFileActivated (object sender, EventArgs e) { FileChooserDialog fcd = new FileChooserDialog ("Ouvrir ...", this.Parent as Gtk.Window, FileChooserAction.Open, "Annuler", ResponseType.Cancel, "Ouvrir", ResponseType.Accept); fcd.SelectMultiple = true; /*fcd.Filter = new FileFilter (); fcd.Filter.AddPattern ("*.mp3");*/ if ((ResponseType)fcd.Run () == ResponseType.Cancel || fcd.Filename == null) { fcd.Destroy (); return; } int pos = IndexSelection (); foreach (var file in fcd.Filenames) { pos = sequenceur.AddFile (pos + 1, file ); if(sequenceur.CurFile.Equals(string.Empty)) sequenceur.Index=0; } fcd.Destroy (); UpdListFiles(); } void SelectionneLigne(){ int index = sequenceur.Index; listFiles.SetCursor( new TreePath( new int[1] {index }) ,null,false); } protected void OnActDelFileActivated (object sender, EventArgs e) { int pos = IndexSelection(); if (pos==-1) return; sequenceur.DelFile(pos); UpdListFiles(); } protected void OnBtnNextClicked (object sender, EventArgs e) { sequenceur.Index+=1; listFiles.QueueDraw(); SelectionneLigne(); } protected void OnBtnPlayClicked (object sender, EventArgs e) { sequenceur.Play(); } protected void OnBtnPauseClicked (object sender, EventArgs e) { sequenceur.Pause(); } protected void OnBtnStopClicked (object sender, EventArgs e) { sequenceur.Stop(); } protected void OnBtnPrevClicked (object sender, EventArgs e) { sequenceur.Index-=1; listFiles.QueueDraw(); SelectionneLigne(); } protected void OnBtnRewindPressed (object sender, EventArgs e) { rw=true; } protected void OnBtnRewindReleased (object sender, EventArgs e) { rw=false; } protected void OnBtnForwardPressed (object sender, EventArgs e) { ff=true; } protected void OnBtnForwardReleased (object sender, EventArgs e) { ff=false; } protected void OnSclVolumeValueChanged (object sender, EventArgs e) { sequenceur.Volume = (uint)(sclVolume.Value); } protected void OnBtnGotoClicked (object sender, EventArgs e) { TimeSpan ts; string[] formats = new string[]{ @"m\:s\.f", @"m\:s", @"h\:m\:s", @"h\:m\:s\.f" }; if(!TimeSpan.TryParseExact(txtGoto.Text,formats,null,out ts)) return; sequenceur.PlayTime = ts; } protected void OnListFilesCursorChanged (object sender, EventArgs e) { TreeViewColumn col; TreePath path; listFiles.GetCursor (out path, out col); if (listFiles.Columns [0] == col) { sequenceur.Index = IndexSelection(); } } #endregion } }