Skip to main content
Topic: bug in NWC2ClipItem? (Read 12990 times) previous topic - next topic

bug in NWC2ClipItem?

With the recent expansion from "clip text" to "file text", I wonder if the intention is to allow use of NWC2ClipItem for file properties, staff properties, and staff lyrics, in addition to the staff notations it was originally designed for.  It is basically already there as far as I can tell, except for one "bug".  I've noticed that if I set the Title/Author/Lyricist/etc to an empty string in an NWC2ClipItem object and then ReconstructClipText, the empty string value gets dropped.  For example, "Title" => "" becomes simply '|Title' instead of '|Title:""' as expected.  Then NWC sees a text label with no field value and does not overwrite the value it has.  This prevents a file text script from clearing a SongInfo field.  [Interestingly, if NWC sees even just '|Title:' it clears the field, so the colon is the key, not the quotes.]

The problem is that ReconstructClipText assumes that an empty string value is indicative of a "flag" field, and just moves the key into the nwctxt without any value.  Only after that does it test the opt tag classification for text and add quotes if so.  If the empty string handling could be suppressed for text opt tags, the subsequent quoting code would do what we want I think.  [As an alternative fix, NWC could change its behaviour upon a field label with no text value, and assume that means to set the field to an empty string, rather than simply ignoring the field label.  The text staff notations (e.g. Instrument/Name) seem to already have this behaviour.]

Bottom line: I'd like to be able to set any text-based field to an empty string in a clip item object, and have that make it back to NWC as a "clear field" operation.

Re: bug in NWC2ClipItem?

Reply #1
If anyone is interested in surveying NWC's handling of text-based fields wrt to which can currently be cleared and which cannot (I did not thoroughly do this), here is a list of them:

File properties:
  • All SongInfo fields - Title, Author, Lyricist, Copyright1, Copyright2, Comments
  • Font field - Typeface

Staff properties:
  • All (current) AddStaff fields - Name, Label, Group
  • StaffInstrument field - Name

Staff lyrics:
  • Lyric1 through Lyric8 field - Text

Staff notations:
  • Tempo field - Name
  • Text field - Text
  • Instrument field - Name

Re: bug in NWC2ClipItem?

Reply #2
I've noticed that if I set the Title/Author/Lyricist/etc to an empty string in an NWC2ClipItem object and then ReconstructClipText, the empty string value gets dropped. 
Instead of an empty string, try null
Registered user since 1996

 

Re: bug in NWC2ClipItem?

Reply #3
Hi Rick - Sorry, didn't see your post until just now - The null trick will indeed work great, and will clean up my workaround a bit, becoming:
Code: [Select · Download]
class NWC2ClipItemWithWorkaround extends NWC2ClipItem {
   function ReconstructClipText() {
      foreach ($this->Opts as $k => &$v)
        if ($v === "")
           if (NWC2ClassifyOptTag($this->ObjType, $k) == NWC2OPT_TEXT)
              $v = null;

      return parent::ReconstructClipText();
   }
}
Thanks for the tip!