Results 1 to 6 of 6

Thread: Finding info in textareas

  1. #1
    Join Date
    Sep 2008
    Jackson MS

    Question Finding info in textareas

    I am trying to read something like the following in a textarea
    There are other types of records but I am only interested in the ones which start with "|Note|". The field after "Pos:" will be compared to members of:
     var offsets = [ "n-6", "#-6", "n-5", "#-5", "n-4", "n-3", ... ]
    If there are other fields after Pos:, there will be a "|" or "!" instead of the end of the line.

    I was able to run the split("\n") command against the textarea to break it into separate lines, but I couldn't search those lines.

    I hope to add this as a new feature to ttr.htm.


  2. #2
    Join Date
    Dec 2009
    Can you post the code, especially where the split is.

  3. #3
    Join Date
    Sep 2008
    Jackson MS
    It should be able to read the data it just produced. After "Click", "Read" tests what I am working on.

    <title>Generate twelve tone row</title>
    <script language="JavaScript">
      var deck = new Array();
      var seltab = new Array();
      var keyOffset;
    function startup() {
      document.nwcform.selAll.checked = true;
    function calculate(parm) {
      var offsets = [ "n-6", "#-6", "n-5", "#-5", "n-4", "n-3", "#-3", "n-2", "#-2", "n-1", "#-1", "n0",
       "n1", "#1", "n2", "#2", "n3", "n4", "#4", "n5", "#5", "n6", "#6" ];
      var i, j, OutText = "", testflags = "00000000000000000000";  // 25 of 'em.
      if (parm == 0) {  //Create random permutation
        keyOffset = document.nwcform.Key.selectedIndex;   
        for (i=0; i < 12; i++)
          deck[i] = i;
        for (j = 11; j > -1; j--) {
          var r = Math.floor(Math.random() * j); // Pick one from those remaining
          seltab[j] = deck[r];
          deck[r] = deck[j]; } // Move last of those remaining to slot just chosen 
      else {  // Code to read "OutputField" to determine sequence and key goes here
        var cntNotes=0;
        var lines = new Array();
        lines = document.nwcform.OutputField.value.split("\n");
        for (i=0; lines[i]; i++) {
           var tstr = lines[i];		
    	   if (tstr.test("Note")) 
    	    for (var k = 0; k < offsets.length; k++) {  
    		  if (tstr.search(offsets[k])) {
    			testflags[k] = 1;
                alert(testflags);			}
      }   //End of code to read OutputField
      OutText = "!NoteWorthyComposerClip(2.0,Single)\n";
      for (i=0; i < 12; i++) {
        OutText += "|Note|Dur:4th|Pos:" + offsets[seltab[i] + keyOffset] + "\n";
        deck[i] = seltab[i]; }
      if (document.nwcform.I1.checked) {
        OutText += "|Rest|Dur:4th|Color:0|Visibility:Default\n|Bar|Style:Single|XBarCnt:N|SysBreak:N|Color:0|Visibility:Default\n";
        OutText += '|Text|Text:"Inversion"|Font:PageSmallText|Pos:-6|Wide:N|Justify:Left|Placement:BestFit|Color:0|Visibility:Default\n';
          for (i=0; i < 12; i++) {
            seltab[i] = 11 - deck[i]; 
            OutText += "|Note|Dur:4th|Pos:" + offsets[seltab[i] + keyOffset] + "\n"; } }
      if (document.nwcform.R1.checked) {
        OutText += "|Rest|Dur:4th|Color:0|Visibility:Default\n|Bar|Style:Single|XBarCnt:N|SysBreak:N|Color:0|Visibility:Default\n";
        OutText += '|Text|Text:"Retrograde"|Font:PageSmallText|Pos:-6|Wide:N|Justify:Left|Placement:BestFit|Color:0|Visibility:Default\n';
          for (i=11; i > -1; i--) {
            seltab[i] = deck[i];
            OutText += "|Note|Dur:4th|Pos:" + offsets[seltab[i] + keyOffset] + "\n"; } }
      if (document.nwcform.IR1.checked) {
        OutText += "|Rest|Dur:4th|Color:0|Visibility:Default\n|Bar|Style:Single|XBarCnt:N|SysBreak:N|Color:0|Visibility:Default\n";
        OutText += '|Text|Text:"Invert Retro"|Font:PageSmallText|Pos:-6|Wide:N|Justify:Left|Placement:BestFit|Color:0|Visibility:Default\n';
          for (i=11; i > -1; i--) {
            seltab[i] = 11 - deck[i]; 
            OutText += "|Note|Dur:4th|Pos:" + offsets[seltab[i] + keyOffset] + "\n"; } }
      OutText += "!NoteWorthyComposerClip-End";
      document.nwcform.OutputField.value = OutText;
      if (document.nwcform.selAll.checked == true)
    	// New code to check out split
    	//var tmp = new Array();
    	//tmp = OutText.split("\n");
    	//for (var x = 0; tmp[x]; x++) {
    	//  alert(x + " " + tmp[x]); }
    	//End new code
    <body onload="startup()">
    <form name="nwcform" onSubmit="calculate();return false;">
      <table width="782" height="350">
          <td colspan="4" width="1000" height="24">
            <b><big>Generate twelve tone row to be used in NoteWorthy Composer 2:</big></b>
        <tr><td width="131" height="25">Bottom note: <select name="Key">
              <option selected="SELECTED" value="C ">C </option>
              <option value="C#">C#</option>
              <option value="D ">D </option>
              <option value="D#">D#</option>
              <option value="E ">E </option>
              <option value="F ">F </option>
              <option value="F#">F#</option>
              <option value="G ">G </option>
              <option value="G#">G#</option>
              <option value="A ">A </option>
              <option value="A#">A#</option>
              <option value="B ">B </option>
            <td width="116"><input type="checkbox" name="I1" value="ON">Inversion</td>
            <td width="138"><input type="checkbox" name="R1" value="ON">Retrograde</td>
            <td width="721"><input type="checkbox" name="IR1" value="ON">Invert Retro</td>     
          <td height="27"  width="100"><input type="button" id="bClick1" value="Click" onclick="calculate(0)"></td>
          <td height="27"  width="100"><input type="button" id="bClick2" value="Read" onclick="calculate(1)"></td>
          <td width="602" height="27" colspan="3">Generated code is to be used on a treble clef. &nbsp;For other clefs make appropriate transposition.</td>
        <td colspan=5 width="1044" height="200">
          <textarea name="OutputField" rows="16" cols="120"></textarea></td></tr>
          <tr><td><input type="checkbox" name=selAll value="ON">Select All</td></tr>

  4. #4
    Join Date
    Dec 2009
    You have to implicitly convert OutText to a string object before you can use split.

    OutText = OutText.toString();
    var tmp = new Array();
    tmp = OutText.split("\n");

  5. #5
    Join Date
    Sep 2008
    Jackson MS
    The code around ten lines before <body> worked, the code after the first else was able to split out the lines (I think), but I couldn't search for Note on the split lines, much less find out where the Position was in the offset table.

    Thanks for looking.

  6. #6
    Join Date
    Jul 2008
    urbana, il
    Quote Originally Posted by harrierdh View Post
    You have to implicitly convert OutText to a string object before you can use split.

    OutText = OutText.toString();
    var tmp = new Array();
    tmp = OutText.split("\n");
    this is not java, relax your typing.

    1. your code is explicit, not implicit.
    2. since OutText is already a string, there's no need for toString.
    3. you don't need to pre-define arrays.

    so, all the above code is equal to:
    var tmp = OutText.split(/\r?\n/);
    i use a RegExp instead of a string delimiter to uniformly handle mac, linux, and pc line breaks.


    here is a simple example of what i think you're trying to do, feel free to copy and modify.

    //text (in lieu of textarea value for demo)
    var text="\
    //define ok values here:
    var offsets = { "n-6":1, "#-6":1, "n-5":1, "#-5":1, "n-4":1, "n-3":1};
    //create a line array and output buffer:
    var ray=text.split(/\r?\n/), buff=[];
    //loop through lines:
    for (var it, i=0, mx=ray.length; i<mx; i++){
     	if(it.slice(0, 6)=="|Note|"){	it.replace(/Pos\:([^|\n\r!]+)/g,
    		function(j, a){ //test Pos:value and collect the slot # if good:
    			if(offsets[a]){ buff[buff.length]=i; }  
    		});//end replace function
    	}//end if Note
    }//next line
    //show any found slots, listed by line #:
    Last edited by rnd me; 02-19-2010 at 04:12 AM.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center