public TranscriptionPhrase(TranscriptionPhrase kopie)
 {
     this._begin = kopie._begin;
     this._end = kopie._end;
     this._text = kopie._text;
     this._phonetics = kopie._phonetics;
     this.height = kopie.height;
 }
        /// <summary>
        /// V2 serialization
        /// </summary>
        /// <param name="e"></param>
        /// <param name="isStrict"></param>
        public static TranscriptionPhrase DeserializeV2(XElement e, bool isStrict)
        {
            TranscriptionPhrase phr = new TranscriptionPhrase();
            phr.Elements = e.Attributes().ToDictionary(a => a.Name.ToString(), a => a.Value);
            phr.Elements.Remove(isStrict ? "begin" : "b");
            phr.Elements.Remove(isStrict ? "end" : "e");
            phr.Elements.Remove(isStrict ? "fon" : "f");

            phr._phonetics = (e.Attribute(isStrict ? "fon" : "f") ?? EmptyAttribute).Value;
            phr._text = e.Value.Trim('\r', '\n');
            if (e.Attribute(isStrict ? "begin" : "b") != null)
            {
                string val = e.Attribute(isStrict ? "begin" : "b").Value;
                int ms;
                if (int.TryParse(val, out ms))
                    phr.Begin = TimeSpan.FromMilliseconds(ms);
                else
                    phr.Begin = XmlConvert.ToTimeSpan(val);

            }

            if (e.Attribute(isStrict ? "end" : "e") != null)
            {
                string val = e.Attribute(isStrict ? "end" : "e").Value;
                int ms;
                if (int.TryParse(val, out ms))
                    phr.End = TimeSpan.FromMilliseconds(ms);
                else
                    phr.End = XmlConvert.ToTimeSpan(val);
            }

            return phr;
        }
Beispiel #3
0
        void Document_Changed(object sender, DocumentChangeEventArgs e)
        {
            if (ValueElement == null || updating)
                return;

            if (!(ValueElement is TranscriptionParagraph))
            {
                _TextChangedByUser = true;
                ValueElement.Text = editor.Text;
                _TextChangedByUser = false;
                return;
            }

            TranscriptionParagraph par = ValueElement as TranscriptionParagraph;
            string text = editor.Text;
            int offset = e.Offset;
            int removedl = e.RemovalLength;
            int addedl = e.InsertionLength;
            _TextChangedByUser = true;
            if (removedl > 0)
            {
                List<TranscriptionPhrase> todelete = new List<TranscriptionPhrase>();
                int pos = 0;
                foreach (TranscriptionPhrase p in par.Phrases)
                {

                    string etext = (EditPhonetics ? p.Phonetics : p.Text);
                    int len = etext.Length;

                    if (pos + len > offset) //end of phraze is after the deletion
                    {
                        int iidx = offset - pos;
                        if (removedl > len - iidx) //deletion continues after current phrase
                        {

                            if (iidx == 0) //delete whole phrase
                            {
                                removedl -= len;
                                offset = pos + len;
                                todelete.Add(p);
                            }
                            else //shorten phrase
                            {

                                string s = etext.Remove(iidx);
                                if (EditPhonetics)
                                    p.Phonetics = s;
                                else
                                    p.Text = s;

                                removedl -= len - s.Length;
                                offset = pos + s.Length;

                            }
                        }
                        else if (len == removedl) //remove exactly 1 phrase
                        {
                            removedl -= len;
                            offset = pos + len;
                            if (addedl <= 0)
                                todelete.Add(p);
                            else //in case of replace
                            {
                                if (EditPhonetics)
                                    p.Phonetics = "";
                                else
                                    p.Text = "";
                                offset -= etext.Length; ;
                            }
                            break;
                        }
                        else//deletion ends in phrase
                        {
                            string s = (EditPhonetics ? p.Phonetics : p.Text).Remove(iidx, removedl);
                            if (EditPhonetics)
                                p.Phonetics = s;
                            else
                                p.Text = s;
                            break;

                        }
                    }

                    pos += (EditPhonetics ? p.Phonetics.Length : p.Text.Length);
                }

                par.BeginUpdate();
                foreach (var v in todelete) //remove phrases fprom paragraph - should not redraw anything
                    par.Remove(v);
                par.EndUpdate();

            }
            offset = e.Offset;
            if (addedl > 0)
            {
                int pos = 0;
                if (par.Phrases.Count > 0)
                {
                    foreach (TranscriptionPhrase p in par.Phrases)
                    {
                        if (offset <= pos + (EditPhonetics ? p.Phonetics.Length : p.Text.Length)) //insertion
                        {
                            string s = (EditPhonetics ? p.Phonetics : p.Text).Insert(offset - pos, text.Substring(offset, addedl));
                            if (EditPhonetics)
                                p.Phonetics = s;
                            else
                                p.Text = s;
                            break;
                        }
                        pos += (EditPhonetics ? p.Phonetics.Length : p.Text.Length);
                    }
                }
                else
                {
                    var phr = new TranscriptionPhrase() { Text = text };
                    par.BeginUpdate();
                    par.Phrases.Add(phr);
                }
            }

            _TextChangedByUser = false;
        }
Beispiel #4
0
 public PhrasePhoneticsAction(TranscriptionPhrase changedelement, TranscriptionIndex changeIndex, int changeAbsoluteIndex, string oldphonetics)
     : base(ChangeType.Modify, changedelement, changeIndex, changeAbsoluteIndex)
 {
     _oldtstring = oldphonetics;
 }
        void l_SplitRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            if (el.ValueElement is TranscriptionParagraph)
            {

                TranscriptionParagraph par = (TranscriptionParagraph)el.ValueElement;
                par.Parent.BeginUpdate();
                TimeSpan end = par.End;
                TranscriptionParagraph par2 = new TranscriptionParagraph();
                TranscriptionParagraph par1 = new TranscriptionParagraph();

                par1.AttributeString = par2.AttributeString = par.AttributeString;

                par1.Speaker = par2.Speaker = par.Speaker;
                par1.Begin = par.Begin;
                par2.End = end;
                int where = el.editor.CaretOffset;

                int sum = 0;
                for (int i = 0; i < par.Phrases.Count; i++)
                {
                    TranscriptionPhrase p = par.Phrases[i];

                    if (sum + p.Text.Length <= where) //patri do prvniho
                    {
                        par1.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum >= where)
                    {
                        par2.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum <= where && sum + p.Text.Length > where) //uvnitr fraze
                    {
                        int offs = where - sum;
                        double ratio = offs / (double)p.Text.Length;

                        TimeSpan length = p.End - p.Begin;
                        TimeSpan l1 = new TimeSpan((long)(ratio * length.Ticks));

                        TranscriptionPhrase p1 = new TranscriptionPhrase();
                        p1.Text = p.Text.Substring(0, offs);

                        p1.Begin = p.Begin;
                        p1.End = p1.Begin + l1;
                        //if (p1.End <= par.Begin)
                        //    p1.End = par.Begin + TimeSpan.FromMilliseconds(100); //pojistka kvuli nezarovnanejm textum
                        int idx = i;
                        par1.Add(p1);

                        TranscriptionPhrase p2 = new TranscriptionPhrase();
                        p2.Text = p.Text.Substring(offs);
                        p2.Begin = p1.End;
                        p2.End = p.End;

                        par2.Add(p2);
                        par2.Begin = p2.Begin;

                        par1.End = p1.End;

                    }
                    sum += p.Text.Length;
                }//for

                if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))//TODO: the keyboard check should be somewhere else?
                {

                    if (RequestTimePosition != null)
                    {
                        TimeSpan pos;
                        RequestTimePosition(out pos);

                        par1.End = pos;
                        par2.Begin = pos;
                    }

                }

                var parent = par.Parent;
                int indx = par.ParentIndex;

                FixPosSetFor(par.Previous());

                parent.Remove(par);
                parent.Insert(indx, par2);
                parent.Insert(indx, par1);
                parent.EndUpdate();
                ActiveTransctiption = par2;

                this.Dispatcher.Invoke(() =>
                {
                    FixPosTryRestore();
                    SetCaretIn(par2, 0);
                }, DispatcherPriority.Background);

            }
        }
Beispiel #6
0
        void l_SplitRequest(object sender, EventArgs e)
        {
            Element el = (Element)sender;
            if (el.ValueElement is TranscriptionParagraph)
            {

                TranscriptionParagraph par = (TranscriptionParagraph)el.ValueElement;
                par.Parent.BeginUpdate();
                TimeSpan end = par.End;
                TranscriptionParagraph par2 = new TranscriptionParagraph();
                TranscriptionParagraph par1 = new TranscriptionParagraph();

                par1.AttributeString = par2.AttributeString = par.AttributeString;

                par1.Speaker = par2.Speaker = par.Speaker;

                par2.End = end;
                int where = el.editor.CaretOffset;

                int sum = 0;
                for (int i = 0; i < par.Phrases.Count; i++)
                {
                    TranscriptionPhrase p = par.Phrases[i];

                    if (sum + p.Text.Length <= where) //patri do prvniho
                    {
                        par1.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum >= where)
                    {
                        par2.Add(new TranscriptionPhrase(p));
                    }
                    else if (sum <= where && sum + p.Text.Length > where) //uvnitr fraze
                    {
                        int offs = where - sum;
                        double ratio = offs / (double)p.Text.Length;

                        TimeSpan length = p.End - p.Begin;
                        TimeSpan l1 = new TimeSpan((long)(ratio * length.Ticks));

                        TranscriptionPhrase p1 = new TranscriptionPhrase();
                        p1.Text = p.Text.Substring(0, offs);

                        p1.Begin = p.Begin;
                        p1.End = p1.Begin + l1;
                        if (p1.End <= par.Begin)
                            p1.End = par.Begin + TimeSpan.FromMilliseconds(100); //pojistka kvuli nezarovnanejm textum
                        int idx = i;
                        par1.Add(p1);

                        TranscriptionPhrase p2 = new TranscriptionPhrase();
                        p2.Text = p.Text.Substring(offs);
                        p2.Begin = p1.End;
                        p2.End = p.End;

                        par2.Add(p2);
                        par2.Begin = p2.Begin;

                        par1.End = p1.End;

                    }
                    sum += p.Text.Length;
                }//for

                if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control))//TODO: hodit to nejak jinak do funkci... :P
                {

                    if (RequestTimePosition != null)
                    {
                        TimeSpan pos;
                        RequestTimePosition(out pos);

                        par1.End = pos;
                        par2.Begin = pos;
                    }

                }
                //SpeakerChanged();
                var parent = par.Parent;
                int indx = par.ParentIndex;
                parent.Remove(par);
                parent.Insert(indx, par2);
                parent.Insert(indx, par1);
                parent.EndUpdate();
                ActiveTransctiption = par2;
            }
        }
Beispiel #7
0
        private static IEnumerable<TranscriptionParagraph> MakeParagraphs(IEnumerable<XElement> elements, TimeSpan timeunit)
        {
            foreach (var e in elements)
            {
                var p = new TranscriptionParagraph()
                {
                    Begin = new TimeSpan( timeunit.Ticks * XmlConvert.ToInt64(e.Attribute("bt").Value)),
                    End = new TimeSpan( timeunit.Ticks * XmlConvert.ToInt64(e.Attribute("et").Value)),
                };

                var ph = new TranscriptionPhrase()
                {
                    Begin = p.Begin,
                    End = p.End,
                    Text = "",
                };

                var idel = e.Element("Id");
                if (idel != null)
                {
                    p.InternalID = XmlConvert.ToInt32(idel.Attribute("id").Value);
                    ph.Text = "score: "+idel.Attribute("score").Value;
                }
                p.Phrases.Add(ph);
                yield return p;
            }
        }