/* 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 System.Collections.ObjectModel; using System.Linq; using System.Threading; namespace DMX2 { public class SequenceurSon : Sequenceur { SeqSonUI ui=null; static bool gsinit=false; List files = new List(); string curfile = string.Empty; uint volume=100; Gst.Element element = null; public ReadOnlyCollection Files { get { return files.AsReadOnly(); } } public string CurFile { get{return curfile; } } public int Index { get { return files.IndexOf (curfile); } set { if(value>=0 && value< files.Count) LoadFile(value); } } public int AddFile (int pos, string file) { lock (this) { files.Insert (pos, file); //CommandAdd(pos); return pos; } } public uint Volume { get{ return volume;} set { volume=value; if(element!=null) element["volume"] = (double)volume / 100.0d ; } } public void DelFile (int pos) { lock (this) { files.RemoveAt (pos); //CommandRemove(pos); } } void LoadFile (int pos) { curfile = files[pos]; if (element != null) { element.SetState(Gst.State.Null); element.Dispose(); } Uri uri = new Uri(curfile); element = Gst.ElementFactory.Make("playbin2"); element["uri"] = uri.AbsoluteUri; element.SetState(Gst.State.Paused); } public void Play () { if(element == null)return; element.SetState(Gst.State.Playing); } public void Pause () { if(element == null)return; element.SetState(Gst.State.Paused); } public void Stop () { if(element == null)return; element.SetState(Gst.State.Null); element.Dispose(); element=null; } public void MoveTo(ulong pos){ } static void GstInit () { if(gsinit) return; gsinit=true; string[] args = new string[] {"--gst-disable-segtrap"}; Gst.Application.Init("dmx2", ref args ); } public SequenceurSon () { GstInit(); } #region implemented abstract members of DMX2.Sequenceur public override SequenceurUI GetUI () { if (ui == null) { ui = new SeqSonUI (this); ui.Destroyed += UiDestroyed; } return ui; } void UiDestroyed (object sender, EventArgs e) { //throw new NotImplementedException (); } public override int ValeurCircuit (Circuit c) { return 0; } public override void Tick (TimeSpan time) { //throw new System.NotImplementedException (); } public override void Save (System.Xml.XmlElement parent) { //throw new System.NotImplementedException (); } public override void Command (string command) { //throw new System.NotImplementedException (); } #endregion } }