Example #1
0
void TNotesResource1::Get(TEndpointContext* AContext, TEndpointRequest* ARequest,
	TEndpointResponse* AResponse)
{
	String LTitle = "";
	std::auto_ptr<TNote> LNote(new TNote());
	std::vector<TNote*> * lNotes = NULL;
	TJSONArray * lJson = NULL;
	try {
		this->CheckNotesManager(AContext);
		if(ARequest->Params->TryGetValue("title", LTitle)) {
			// Find a note with a particular title
			if(FNotesStorage->FindNote(LTitle, LNote.get())) {
				lNotes = new std::vector<TNote*>();
				lNotes->push_back(LNote.get());
			}
			else {
				lNotes = NULL;
			}
		}
		else {
			lNotes = FNotesStorage->GetNotes();
		}
		lJson = TNoteJSON::NotesToJSON(lNotes);
		AResponse->Body->SetValue(lJson, true);
	}
	catch(...) {
		FreeAndNil(lJson);
		HandleException();
	}
}
Example #2
0
LNote Lilypond::scanNote()
      {
      QChar c   = lookup();
      int pitch = 48;

      switch (c.toAscii()) {
            case 'a':   pitch += 9; break;
            case 'b':   pitch += 11; break;
            case 'c':   break;
            case 'd':   pitch += 2; break;
            case 'e':   pitch += 4; break;
            case 'f':   pitch += 5; break;
            case 'g':   pitch += 7; break;
            }
      ++ci;
printf("scanNote pitch %d relpitch %d\n", pitch, relpitch);
      if (relpitch > 0) {
            if (pitch < relpitch) {
                  while ((relpitch - pitch) > 5)
                        pitch += 12;
                  }
            else if (pitch > relpitch) {
                  while ((pitch - relpitch) > 5)
                        pitch -= 12;
                  }
            }
      int octave = 0;
      for (;;) {
            if (data[ci] == ' ' || data[ci] == '\n')
                  break;
            if (data[ci] == '\'') {
                  ++octave;
                  ++ci;
                  }
            else if (data[ci] == ',') {
                  --octave;
                  ++ci;
                  }
            else if (data[ci].isLetterOrNumber()) {
                  QString buffer;
                  while (data[ci].isLetterOrNumber())
                        buffer.append(data[ci++]);
                  int len = buffer.toInt();
                  switch(len) {
                        case 1:  curLen = MScore::division * 4; break;
                        case 2:  curLen = MScore::division * 2; break;
                        case 4:  curLen = MScore::division;     break;
                        case 8:  curLen = MScore::division / 2; break;
                        case 16: curLen = MScore::division / 4; break;
                        case 32: curLen = MScore::division / 8; break;
                        case 64: curLen = MScore::division / 16; break;
                        default:
                              printf("illegal note len %d\n", len);
                              break;
                        }
                  }
            else if (data[ci] == '.') {
                  curLen += (curLen / 2);
                  ++ci;
                  }
            }
      pitch += octave * 12;
      if (relpitch > 0)
            relpitch = pitch;
      return LNote(pitch, curLen);
      }