Example #1
0
    public static void SoundGroupScript(LMGroupSound root) {
      if (root == null) return;
      bool playerGenerated = false;
      StringBuilder sb = null;
      Dictionary<string, sndFileInfo> files = new Dictionary<string, sndFileInfo>();
      int cnt = 0;
      foreach (LMGroupSound snd in root)
        foreach (LMGroupSound interval in snd) {
          string spaceId, globalId, url;
          interval.markers.getObjId(out spaceId, out globalId, out url);
          if (!files.ContainsKey(url)) files.Add(url, new sndFileInfo(cnt++, spaceId, globalId));
        }
      cnt = 0;
      ConfigLow crsConfig = Deployment.actConfig(null);
      SoundPlayerType sndDriver = crsConfig.LMS == LMSType.SlNewEE ? SoundPlayerType.SlNewEE : SoundPlayerType.no;
      foreach (LMGroupSound snd in root) {
        if (snd.sound.ignoreSound() != sound_dialogIgnore_sound.no) continue;
        snd.varName = string.Format("sg{0}", cnt++);
        if (!playerGenerated) {
          /*
          LMScormLib.LMScormClientScript.RegisterAjaxScript("S4N.SoundPlayer",
            new LMScormLib.AjaxPairs("email", "soundPlayer", "forceVersion", "#sS4N.SoundDriver." + sndDriver.ToString()),
            new LMScormLib.AjaxPairs("onSentFocus", "snd_sentenceFocus", "onMarkFocus", "snd_markFocus"),
            null, null);*/
          playerGenerated = true;
          foreach (KeyValuePair<string, sndFileInfo> kv in files)
            LMScormLib.LMScormClientScript.RegisterAjaxScript("S4N.SoundFile",
              new LMScormLib.AjaxPairs("id", "sf" + kv.Value.id.ToString(), "url", kv.Key, "spaceId", kv.Value.spaceId, "globalId", kv.Value.globalId),
              null, new LMScormLib.AjaxPairs("player", "soundPlayer"), null);
          sb = new StringBuilder();
        }
        //poradi intervalu v grupe
        sb.Length = 0;
        sb.Append("#s[");
        for (int i = 0; i < snd.Count; i++) {
          LMGroupSound interval = (LMGroupSound)snd[i];
          sb.Append('\''); sb.Append(interval.varName); sb.Append('\'');
          if (i < snd.Count - 1) sb.Append(',');
        }
        sb.Append(']');
        LMScormLib.LMScormClientScript.RegisterAjaxScript("S4N.SoundGroup",
          new LMScormLib.AjaxPairs("id", snd.varName, "intervals", sb.ToString()), null, new LMScormLib.AjaxPairs("player", "soundPlayer"), null);
        if (snd.mark != null)
          LMScormLib.LMScormClientScript.RegisterAjaxScript("S4N.SoundMark", null, null, new LMScormLib.AjaxPairs("group", snd.varName), snd.mark.varName);

        for (int i = 0; i < snd.Count; i++) {
          LMGroupSound interval = (LMGroupSound)snd[i];
          string spaceId, globalId, url;
          interval.markers.getObjId(out spaceId, out globalId, out url);
          int fileId = files[url].id;
          LMScormLib.Marker begMark = interval.markers[((sound_sentence)interval[0]).markIdx];
          LMScormLib.Marker endMark = interval.markers[((sound_sentence)interval[interval.Count - 1]).markIdx];
          LMScormLib.LMScormClientScript.RegisterAjaxScript("S4N.SoundInterval",
            new LMScormLib.AjaxPairs("id", interval.varName, "beg", (int)(begMark.Beg / 10000), "end", (int)(endMark.End / 10000)), null, new LMScormLib.AjaxPairs("file", "sf" + fileId.ToString()), null);
          foreach (sound_sentence sent in interval) {
            LMScormLib.Marker mark = interval.markers[sent.markIdx];
            LMScormLib.LMScormClientScript.RegisterAjaxScript("S4N.SoundSent",
              new LMScormLib.AjaxPairs("beg", (int)(mark.Beg / 10000), "end", (int)(mark.End / 10000)/*, "endFocus", mark.Middle*/),
              null,
              new LMScormLib.AjaxPairs("interval", interval.varName),
              sent.varName);

          }
        }
      }
      oldToNewSound.run(root);
    }
Example #2
0
 public static IEnumerable<sent> sentFromGroup(LMGroupSound snd) {
   //transformovana lmdata - zjisti lmdata XML s sentences
   Dictionary<string, XElement> sentsXml;
   if (transformedXml != null) {
     var xml = XElement.Parse(transformedXml);
     xml.Descendants().Select(el => el.Name = el.Name.LocalName).ToArray(); //odstran namespace
     sentsXml = xml.Descendants("sound_sentence").ToDictionary(s => s.AttributeValue("id"), s => s);
   } else
     sentsXml = new Dictionary<string, XElement>();
   //transformedXml = null;
   bool? isDialog = null; int sentOrder = 0;
   foreach (var interval in snd.Cast<LMGroupSound>()) {
     if (isDialog == true) throw new Exception("OLD NEW DATA ERROR: by hand operation needed for sound: more than 2 intervals in dialog");
     var oldEndPos = -1;
     string sid, gid, u; sent lastSent = null;
     interval.markers.getObjId(out sid, out gid, out u);
     yield return new sent() { url = "/" + u, sentOrder = sentOrder++, self = null, sentXml = new XElement("phrase", new XAttribute("beg-pos", "0"), new XAttribute("end-pos", "0")) };
     foreach (sound_sentence sent in interval) {
       LMScormLib.Marker mark = interval.markers[sent.markIdx];
       var res = new sent() { url = "/" + u, sentOrder = sentOrder++, self = sent };
       XElement xml = null;
       if (!string.IsNullOrEmpty(sent.id) && sentsXml.TryGetValue(sent.id, out xml)) {
         var desc = xml.DescendantNodes().ToArray();
         if (desc.Length == 0) xml = null;
         else if (desc.Length == 1 && desc[0] is XText && string.IsNullOrEmpty(((XText)desc[0]).Value.Trim(new char[] { '\r', '\n', '\t', ' ' }))) xml = null;
         if (xml != null) { //http://bt.langmaster.cz/com/edit_bug.aspx?id=2139: Obrázek uvnitř lm:sound_sentence má chybnou url aritmetiku
           foreach (var src in xml.Descendants("img").SelectMany(n => n.Attributes("src"))) {
             if (src.Value.StartsWith("~")) src.Value = src.Value.Substring(2).ToLower();
           }
         }
       }
       //dialog?
       res.replica = sent.myReplica();
       if (isDialog == null) isDialog = res.replica != null; else if (isDialog != (res.replica != null)) throw new Exception("OLD NEW DATA ERROR: by hand operation needed for sound: isDialog != (myRole!=null)");
       //ignoreSound
       //res.ignoreSound = getIgnoreSound(sent);
       //if (ignoreSound == null) ignoreSound = res.ignoreSound; else if (ignoreSound != res.ignoreSound) throw new Exception("ignoreSound != res.ignoreSound");
       var oldb = (int)(mark.Beg / 10000);
       if (lastSent != null) {
         oldb = (int)((oldEndPos + oldb) / 2);
         lastSent.sentXml.SetAttributeValue("end-pos", oldb.ToString());
       }
       oldEndPos = (int)(mark.End / 10000);
       res.sentXml = new XElement("phrase", new XAttribute("beg-pos", oldb.ToString()), new XAttribute("end-pos", oldEndPos.ToString()), xml == null ? (Object)mark.Title : xml.Nodes());
       lastSent = res;
       yield return res;
     }
   }
 } public static string transformedXml;
Example #3
0
 IEnumerable<sound_sentence> allSent(LMGroupSound grp) {
   foreach (object obj in grp)
     if (obj is sound_sentence) yield return (sound_sentence)obj;
     else if (obj is LMGroupSound) allSent((LMGroupSound)obj);
     else throw new Exception();
 }
Example #4
0
 public static void run(LMGroupSound root) {
   if (!LMScormLib.HTTPModule.Hack()) return;
   int oldIdIdx = 1;
   foreach (LMGroupSound snd in root) {
     if (snd.sound.ignoreSound() != sound_dialogIgnore_sound.no) continue;
     var sentsAll = sentFromGroup(snd).ToArray();
     var sents = sentsAll.Where(s => s.self != null).ToArray();
     //kontroly
     if (sents.Select(s => s.url).Distinct().Count() != 1) throw new Exception("OLD NEW DATA ERROR: by hand operation needed for sound: two files per sound group exists");
     var isDialog = sents[0].replica != null;
     if (!sents.All(s => (s.replica != null) == isDialog)) throw new Exception("OLD NEW DATA ERROR: by hand operation needed for sound: mix of replica and not replica sentences");
     //doplneni XML do replik nebo do sentences
     XElement cutXml = null; XElement lastMediaText = null; int sentOrder_subset = 0;
     if (isDialog) {
       var repls = sents.GroupBy(s => s.replica).ToArray();
       foreach (var repl in repls) {
         var actMediaTextId = "on_" + (oldIdIdx++).ToString();
         //sound mark
         if (snd.mark != null && lastMediaText == null)
           snd.mark.oldToNewXml = new XElement("media-big-mark", new XAttribute("share-media-id", actMediaTextId));
         repl.Key.oldToNewXml = new XElement("media-text", new XAttribute("id", actMediaTextId), new XAttribute("subset", sentOrder_subset.ToString()),
           new XAttribute("is-old-to-new", "true"), repl.First().self.layout == sentenceStyle_Type.hidden ? new XAttribute("hidden", "true") : null);
         sentOrder_subset++;
         if (lastMediaText != null)
           lastMediaText.Add(new XAttribute("continue-media-id", actMediaTextId));
         lastMediaText = repl.Key.oldToNewXml;
         if (cutXml == null)
           repl.Key.oldToNewXml.Add(cutXml = new XElement("cut-dialog", new XAttribute("media-url", repl.First().url)));
         cutXml.Add(new XElement("replica", repl.Select(r => r.sentXml), repl.Key.role_text == null ? null : new XAttribute("actor-name", repl.Key.role_text), repl.Key.role_icon == sound_dialogRoleRole_icon.no ? null : new XAttribute("actor-id", repl.Key.role_icon.ToString().ToLower())));
       }
     } else {
       foreach (var sent in sents.Where(s => s.self != null)) {
         var actMediaTextId = "on_" + (oldIdIdx++).ToString();
         //sound mark
         if (snd.mark != null && lastMediaText == null)
           snd.mark.oldToNewXml = new XElement("media-big-mark", new XAttribute("share-media-id", actMediaTextId));
         sent.self.oldToNewXml = new XElement("media-text", new XAttribute("id", actMediaTextId), new XAttribute("subset", sent.sentOrder.ToString()),
           new XAttribute("is-old-to-new", "true"), sent.self.layout == sentenceStyle_Type.hidden ? new XAttribute("hidden", "true") : null);
         if (lastMediaText != null)
           lastMediaText.Add(new XAttribute("continue-media-id", actMediaTextId));
         lastMediaText = sent.self.oldToNewXml;
         if (cutXml == null)
           sent.self.oldToNewXml.Add(cutXml = new XElement("cut-text", new XAttribute("media-url", sent.url), sentsAll.Select(s => s.sentXml)));
       }
     }
   }
 }