コード例 #1
0
PianoGridNote* PianoGrid::getNote (const int noteNumber, const float beatNumber)
{
    for (int i = notes.size(); --i >= 0;)
        if (getNote (i)->isNoteToggled (noteNumber, beatNumber))
            return getNote (i);
    return 0;
}
コード例 #2
0
bool CUserItem::getAsString( wxString& strUser )
{
    wxString wxstr;
    strUser.Empty();
        
    strUser += wxString::Format( _("%ld;"), getUserID() );
    strUser += getUser();
    strUser += _(";");
    // Protect password
    wxstr = getPassword();
    for ( int i=0; i<wxstr.Length(); i++ ) {
        strUser += _("*");
    }
    //strUser += getPassword();
    strUser += _(";");
    strUser += getFullname();
    strUser += _(";");
    vscp_writeFilterToString( getFilter(), wxstr );
    strUser += wxstr;
    strUser += _(";");
    vscp_writeMaskToString( getFilter(), wxstr );
    strUser += wxstr;
    strUser += _(";");
    strUser += getUserRightsAsString();
    strUser += _(";");
    strUser += getAllowedRemotesAsString();
    strUser += _(";");
    strUser += getAllowedEventsAsString();
    strUser += _(";");
    strUser += wxBase64Encode( getNote().mbc_str(), strlen( getNote().mbc_str() ) ); 	
    //strUser += getNote();
    
    return true;
}
コード例 #3
0
void MainWindow::showNotificationAboutTimout()
{
    auto timer = static_cast<CountdownTimer *>(sender());
    icon.showMessage("Timeout", QString("Note: %1\n Time: %2").arg(timer->getNote()).arg(timer->getTime().toString("HH:mm:ss")));
    player.setMedia(QUrl("qrc:/media/notification"));
    player.play();
}
コード例 #4
0
int PianoGrid::getNoteIndex (const int noteNumber, const float beatNumber)
{
    for (int i = notes.size(); --i >= 0;)
        if (getNote (i)->isNoteToggled (noteNumber, beatNumber))
            return i;
    return -1;
}
コード例 #5
0
ファイル: log.cpp プロジェクト: AngryAccelerated/MonitorV2
QString Log::getLogString(){
    return QString(QObject::tr("%1 [%2] `%4` <%5> : %3")).arg(time.toString("yyyy/MM/dd hh:mm:ss"))
            .arg(getTypeName())
            .arg(getText())
            .arg(getNote())
            .arg(getReturnValue());
}
コード例 #6
0
ファイル: Card.cpp プロジェクト: AirBayCreative/GameCards
String Card::getAll() {
	String all = getQuantity()+","+getText()+","+getThumb()+","+getFront()+
			","+getBack()+","+getId()+","+getRate()+","+getValue()+","+getNote()+","+getOrientation()+",";
	for (int i = 0; i < stats.size(); i++) {
		all += stats[i]->getAll() + "$";
	}
	return all;
}
コード例 #7
0
QModelIndex NotesUiModel::getIndexByNote(const NoteDto &note) {
    for (int row=0; row < rowCount(); ++row ) {
        if (getNote(index(row)).getId() == note.getId()) {
            return index(row);
        }
    }
    return QModelIndex();   // empty invalid index (isValid()=false)
}
コード例 #8
0
ファイル: aservelib.cpp プロジェクト: tommymitch/Aserve
int aserveGetNoteChannel()
{
	MidiMsg note = getNote();	
	if(note.statusbyte == -1)
		return -1;//set when the bytes are in initial state
		
	return note.statusbyte & 0x0f;
}
コード例 #9
0
void PianoGrid::resized ()
{
    for (int i = notes.size(); --i >= 0;)
    {
        PianoGridNote* note = getNote (i);
        note->setBounds (getNoteRect (note));
    }
	
	MidiGrid::resized();
}
コード例 #10
0
ファイル: KeyItem.cpp プロジェクト: kushview/ksp1
    LayerItem KeyItem::addLayer (const LayerItem& layer)
    {
        int layerIndex = countLayers();
        ValueTree lnode = layer.node().createCopy();
        lnode.setProperty (Slugs::index, layerIndex, nullptr);
        lnode.setProperty (Slugs::note, getNote(), nullptr);
        LayerItem item (lnode);
        objectData.addChild (lnode, layerIndex, nullptr);

        return item;
    }
コード例 #11
0
ファイル: music.cpp プロジェクト: JaeimPark/Work-in-progress
	void operator()()
	{
		char* melody = "c-g-c-g-c-g-cchag-d-g-d-g-d-ggahc-g-c-g-c-g-ccdef-c-f-c-f-c-ffedc-g-c-g-c-g-cchag-d-g-d-g-d-ggah";
		int nLen = strlen(melody);
		char ch = 0;

		LONG lPassed = GetPassedTime();

		if ( m_bPlaying )
		{
			float fPassedSeconds = lPassed / 1000.0f;

			if ( m_fFreqMultiplyStep != 0 )
			{
				m_fFreqMultiply += m_fFreqMultiplyStep * fPassedSeconds / 0.6f; // 0.6s intro
				if ( m_fFreqMultiply > 1.0f )
					m_fFreqMultiply = 1.0f;
				if ( m_fFreqMultiply < 0.0f )
					m_fFreqMultiply = 0.0f;
			}

			float fNotesPerSecond = m_fTempo / 60.0f;

			if ( m_fFreqMultiply == 1.0f )
				m_fPosition += fPassedSeconds * fNotesPerSecond;

			int nPos = ((int)m_fPosition);

			if ( m_fFreqMultiply < 1.0f && melody[nPos%nLen] == '-' )
			{
				m_fPosition++;
				nPos++;
			}

			if ( m_fFreqMultiply < 1.0f || m_fPosition - nPos <= 0.80 ) // 20% legato
			{
				nPos %= nLen;
				ch = melody[nPos];
			}
		}

		int note1 = getNote(ch);

		// not time-fixed
		for (int key=0;key<KEYS;key++)
		{
			if ( (note1 == key) && vol[key]<MAXVOL) {
				pos[key]=0;
				vol[key]=(float)(MAXVOL+DECAY/2); // start key (setting "vol" slightly higher than MAXVOL to cover any rounding-down)
			} else if (!(note1 == key) && vol[key])
				vol[key]-=(float)DECAY; // trigger key fadeout
		}		
	}
コード例 #12
0
ファイル: KeyItem.cpp プロジェクト: kushview/ksp1
    LayerItem KeyItem::addLayer (const File& file)
    {
        const int layerIndex  = countLayers();
        ValueTree layerNode (Tags::layer);

        layerNode.setProperty (Slugs::index, layerIndex, nullptr);
        layerNode.setProperty (Slugs::file, file.getFullPathName(), nullptr);
        layerNode.setProperty (Slugs::name, file.getFileNameWithoutExtension(), nullptr);
        layerNode.setProperty (Slugs::note, getNote(), nullptr);

        LayerItem layer (layerNode);
        objectData.addChild (layerNode, layerIndex, nullptr);

        return layer;
    }
コード例 #13
0
ファイル: music.c プロジェクト: juanmbellini/Kernel-Arqui
void pianoPlay(void) {

	uint16_t note;
	while(1) {

		note = getNote();

		if (note == 1) {
			break;
		}
		playNote(note);
		sleep(56); /* minimum sleep time */
	}

}
コード例 #14
0
ファイル: midiarp.cpp プロジェクト: milkmiruku/qmidiarp
void MidiArp::updateNotes()
{
    int l1 = 0;

    //allow 8 ticks of tolerance for echo tick for external sync
    if ((currentTick + 8) >= currentNoteTick) {
        currentNoteTick = nextTick;
        getNote(&nextTick, nextNote, nextVelocity, &nextLength);
        while ((nextNote[l1] >= 0) && (l1 < MAXCHORD - 1)) {
            currentNote[l1] = nextNote[l1];
            currentVelocity[l1] = nextVelocity[l1];
            l1++;
        }
        currentNote[l1] = -1; // mark end of chord
        currentLength = nextLength;
        newCurrent = true;
        newNext = true;
    }
}
コード例 #15
0
ファイル: Guitar.cpp プロジェクト: M-Mueller/TonARt
// For a midi "note number" <--> "note name" <--> "frequency" table , see http://tonalsoft.com/pub/news/pitch-bend.aspx
void Guitar::startMidiOutput()
{
	std::vector<unsigned char> message;
	message.push_back( 0xC0 );
	message.push_back( 25 );	// Instrument
	MidiInstrument::s_midiout->sendMessage( &message );

	// Control Change: 176, 7, 100 (volume)
	message[0] = 0xB0;
	message[1] = 7;
	message.push_back( 50 );
	MidiInstrument::s_midiout->sendMessage( &message );

	// Note On: 144, 64, 90
	message[0] = 0x90;
	message[1] = MidiInstrument::s_midiNotes[getNote()];	// tonhoehe
	message[2] = 64;	// dynamik
	MidiInstrument::s_midiout->sendMessage( &message );

}
コード例 #16
0
ファイル: notehistory.cpp プロジェクト: Fabijenna/QOwnNotes
bool NoteHistoryItem::isNoteValid() {
    Note note = getNote();
    return note.exists();
}
コード例 #17
0
ファイル: BMSData.cpp プロジェクト: kuna/LR2csv
bool BMSData::isNoteAlreadyExists(int beat, int numerator, int channel, int layer) {
	return (getNote(beat, numerator, channel, layer) != 0);
}
コード例 #18
0
void SimpleMIDIPlayer::stopNote( NotesEnum note, int octave ){
	sendMIDIEvent(	outHandle, 0x80, getNote(note, octave) , 127 );
}
コード例 #19
0
ファイル: iopae.cpp プロジェクト: rondini/verovio
void PaeInput::parsePlainAndEasy(std::istream &infile) {
    // buffers
    char c_clef[1024] = {0};
    char c_key[1024] = {0};
    char c_keysig[1024] = {0};
    char c_timesig[1024] = {0};
    char c_alttimesig[1024] = {0};
    char incipit[10001] = {0};
    int in_beam = 0;
    
    std::string s_key;
    MeasureObject current_measure;
    NoteObject current_note;
    Clef *staffDefClef = NULL;
    
    std::vector<MeasureObject> staff;
    
    // read values
    while (!infile.eof()) {
        infile.getline(data_line, 10000);
        if (infile.eof()) {
            LogDebug("Truncated file or ending tag missing");
            //exit(1);
        }
        getAtRecordKeyValue(data_key, data_value, data_line);
        if (strcmp(data_key,"end")==0) {   
            break;
        } else if (strcmp(data_key,"clef")==0) { 
            strcpy( c_clef, data_value );
        } else if (strcmp(data_key,"key")==0) { 
            strcpy( c_key, data_value );
        } else if (strcmp(data_key,"keysig")==0) { 
            strcpy( c_keysig, data_value );
        } else if (strcmp(data_key,"timesig")==0) { 
            strcpy( c_timesig, data_value );
        } else if (strcmp(data_key,"alttimesig")==0) { 
            strcpy( c_alttimesig, data_value );
        } else if (strcmp(data_key,"data")==0) { 
            strcpy( incipit, data_value );
        }
    }
    
    if (strlen(c_clef)) {
        Clef *c = new Clef;
        getClefInfo(c_clef, c );    // do we need to put a default clef?
        if (!staffDefClef) staffDefClef = c;
        else current_measure.clef = c;
    }

    if (strlen(c_keysig)) {
        KeySig *k = new KeySig();
        getKeyInfo( c_keysig, k);
        current_measure.key = k;
    }
    if (strlen(c_timesig)) {
        MeterSig *meter = new MeterSig;
        getTimeInfo( c_timesig, meter);
        // What about previous values? Potential memory leak? LP
        current_measure.meter = meter;
    }   
    
    // read the incipit string
    size_t length = strlen(incipit);
    int i = 0;
	while(i < length) {
        // eat the input...
        
		if (incipit[i] == ' ') {
            // just skip
            i++;
        }
        
        // octaves
        if ((incipit[i] == '\'') || (incipit[i] == ',')) {
            i += getOctave( incipit, &current_note.octave, i );
        }
        
        // rhythmic values
        else if (isdigit(incipit[i]) != 0) {
            i += getDurations( incipit, &current_measure, i );
        }
        
        //accidentals (1 = n; 2 = x; 3 = xx; 4 = b; 5 = bb)    
        else if (incipit[i] == 'n' || incipit[i] == 'x' || incipit[i] == 'b') {
            i += getAccidental( incipit, &current_note.accidental, i );
        }
        
        //
        // beaming starts
		else if (incipit[i] == '{') {
			//current_note.beam = 1;
            current_note.beam = BEAM_INITIAL;
            in_beam++;
        }
        
        // beaming ends
		else if (incipit[i] == '}' && in_beam > 0) {
            current_measure.notes[current_measure.notes.size() - 1].beam = BEAM_TERMINAL;
            current_note.beam = 0;
            in_beam--;
		}
		
        // slurs are read when adding the note
		else if (incipit[i] == '+') {
        }
        
		// beginning tuplets & fermatas
		else if (incipit[i] == '(') {
            i += getTupletFermata( incipit, &current_note, i );
		}
        
        // end of tuplets
		else if ((incipit[i] == ';') || (incipit[i] == ')')) {
            i += getTupletFermataEnd( incipit, &current_note, i );
		}
        
		// trills are read when adding the note
		else if (incipit[i] == 't') {
        }
        
		//grace notes
		else if ((incipit[i] == 'g') || (incipit[i] == 'q')) {
			i += getGraceNote( incipit, &current_note, i );
		}
		
        
        // end of appogiatura
		else if (incipit[i] == 'r') {
			current_note.appoggiatura = 0; // should not have to be done, but just in case
        }
        
        //note and rest
        // getNote also creates a new note object
        else if (((incipit[i]-'A'>=0) && (incipit[i]-'A'<7)) || (incipit[i]=='-')) {
            i += getNote( incipit, &current_note, &current_measure, i );
        }
        
  		// whole rest
		else if (incipit[i] == '=') {
            i += getWholeRest( incipit, &current_measure.wholerest, i );		
		} 
        
		// abbreviation
        else if (incipit[i] == '!') {
            i += getAbbreviation( incipit, &current_measure, i );
        }
        
        // measure repetition
        else if ((incipit[i] == 'i') && staff.size() > 0) {
            MeasureObject last_measure = staff[staff.size() - 1];
            current_measure.notes = last_measure.notes;
            current_measure.wholerest = last_measure.wholerest;
            
            // if old measure does not end with a tie
            // force the first note of the newly copied measure to be without tie
            // this is to prevent copying tie closes which are invalid
            if (last_measure.notes.size() > 0 && last_measure.notes[last_measure.notes.capacity() - 1].tie == 0)
                current_measure.notes[0].tie = 0;
        }
        
        //barLine
        else if ((incipit[i] == ':') || (incipit[i] == '/')) {
            i += getBarline(incipit, &current_measure.barLine, i);
            current_measure.abbreviation_offset = 0; // just in case...
            staff.push_back( current_measure );
            current_measure.reset();
        }
        
		//clef change
		else if ((incipit[i] == '%') && (i+1 < length)) {
            Clef *c = new Clef;
            i += getClefInfo(incipit, c, i + 1);
            //
            if (!staffDefClef) {
                staffDefClef = c;
            }          
            // If there are no notes yet in the measure
            // attach this clef change to the measure
            else if (current_measure.notes.size() == 0) {
                // If a clef was already assigned, remove it
                if (current_measure.clef)
                    delete current_measure.clef;
                
                current_measure.clef = c;
            } else {
                // as above
                if (current_note.clef)
                    delete current_note.clef;
                
                current_note.clef = c;
            }
        }
        
		//time signature change
		else if ((incipit[i] == '@') && (i+1 < length)) {
            MeterSig *meter = new MeterSig;
            i += getTimeInfo( incipit, meter, i + 1);
            if (current_measure.notes.size() == 0) {
                if (current_measure.meter) {
                    delete current_measure.meter;
                }
                // When will this be deleted? Potential memory leak? LP
                current_measure.meter = meter;
            } else {
                if (current_note.meter) {
                    delete current_note.meter;
                }
                current_note.meter = meter;
            }
        } 
        
  		//key signature change
		else if ((incipit[i] == '$') && (i+1 < length)) {
            KeySig *k = new KeySig;
            i += getKeyInfo( incipit, k, i + 1);
            if (current_measure.notes.size() == 0) {
                if (current_measure.key)
                    delete current_measure.key;
                
                current_measure.key = k;
            } else {
                if (current_note.key)
                    delete current_note.key;
                
                current_note.key = k;
            }
		}
            
        i++;
    }
    
    // we need to add the last measure if it has no barLine at the end
    if (current_measure.notes.size() != 0) {
        //current_measure.barLine = "=-";
        staff.push_back( current_measure );
        current_measure.notes.clear();
    }
    
    
    m_doc->Reset( Raw );
    Page *page = new Page();
    System *system = new System();
    
    int measure_count = 1;
    
    std::vector<MeasureObject>::iterator it;
    for ( it = staff.begin() ; it < staff.end(); it++ ) {
        
        m_staff = new Staff( 1 );
        m_measure = new Measure( true, measure_count );
        m_layer = new Layer( );
        m_layer->SetN( 1 );
        
        m_staff->AddLayer(m_layer);
        m_measure->AddStaff( m_staff );
        system->AddMeasure( m_measure );
        
        MeasureObject obj = *it;
        convertMeasure( &obj );
        measure_count++;
    }

    // add miniaml scoreDef
    StaffGrp *staffGrp = new StaffGrp();
    StaffDef *staffDef = new StaffDef();
    staffDef->SetN( 1 );
    staffDef->SetLines(5);
    if (staffDefClef) {
        staffDef->SetClefShape(staffDefClef->GetShape());
        staffDef->SetClefLine(staffDefClef->GetLine());
        staffDef->SetClefDis(staffDefClef->GetDis());
        staffDef->SetClefDisPlace(staffDefClef->GetDisPlace());
        delete staffDefClef;
    }
    staffGrp->AddStaffDef( staffDef );
    m_doc->m_scoreDef.AddStaffGrp( staffGrp );

    page->AddSystem( system );
    m_doc->AddPage( page );
}
コード例 #20
0
ファイル: main.c プロジェクト: thufoo/Duet-Partner
int
main(int argc, char* argv[]) {

 volatile int16_t note = -1;

 Output_init();
 ADC_init(); // Initialize the ADC
 Timer2_init(); // Initialize Tim2

 while (1) {
  if(index == max_index){//we've finished the song... start over!
   index = 0;
  }
  // Check if a data array is ready for FFT processing
  if(arrayComplete==1){
  arrayComplete = 0; // Reset arrayComplete

   // Process the array that completed!
   if(array1Complete == 1){
    int16_t out = fix_fftr(dataArray1,10,0);
    note = getNote(dataArray1);
    array1Complete = 0;//mark array as available to re-fill
   }
   else if(array2Complete == 1) {
    int16_t out = fix_fftr(dataArray2,10,0);
    note = getNote(dataArray2);
    array2Complete = 0;//mark array as available to re-fill
   }

   int16_t selectedNote = processNote(note);

   switch(selectedNote) {
    case -2:
     // Pause (actually play a frequency so high that no one but dogs can hear it)
     TIM2->ARR = 1000000/40000; // Set frequency (40 kHz)
     break;
    case -1:
     // Continue playing the same note
     break;
    case 0:
     // Generate C4 262 Hz
     TIM2->ARR = 1000000/262/4; // Set frequency
     break;
    case 1:
     // Generate C#4 277 Hz
     TIM2->ARR = 1000000/277/4; // Set frequency
     break;
    case 2:
     // Generate D4 294 Hz
     TIM2->ARR = 1000000/294/4; // Set frequency
     break;
    case 3:
     // Generate D#4 311 Hz
     TIM2->ARR = 1000000/311/4; // Set frequency
     break;
    case 4:
     // Generate E4 330 Hz
     TIM2->ARR = 1000000/330/4; // Set frequency
     break;
    case 5:
     // Generate F4 349 Hz
     TIM2->ARR = 1000000/349/4; // Set frequency
     break;
    case 6:
     // Generate F#4 370 Hz
     TIM2->ARR = 1000000/370/4; // Set frequency
     break;
    case 7:
     // Generate G4 392 Hz
     TIM2->ARR = 1000000/392/4; // Set frequency
     break;
    case 8:
     // Generate G#4 415 Hz
     TIM2->ARR = 1000000/415/4; // Set frequency
     break;
    case 9:
     // Generate A4 440 Hz
     TIM2->ARR = 1000000/440/4; // Set frequency
     break;
    case 10:
     // Generate A# 466 Hz
     TIM2->ARR = 1000000/466/4; // Set frequency
     break;
    case 11:
     // Generate B4 494 Hz
     TIM2->ARR = 1000000/494/4; // Set frequency
     break;
    case 12:
     // Generate C5 523 Hz
     TIM2->ARR = 1000000/523/4; // Set frequency
     break;
    case 13:
     // Generate C#6 554 Hz
     TIM2->ARR = 1000000/554/4; // Set frequency
     break;
    default:
    	break;
   }
  }
 }
}
コード例 #21
0
ファイル: CRoom.cpp プロジェクト: zpc930/pandoramapper
/* ------------------------------ prints the given room --------------------*/
void CRoom::sendRoom() const
{
    unsigned int i, pos;
    char line[MAX_STR_LEN];
    
    send_to_user(" Id: %i, Flags: %s, Region: %s, Coord: %i,%i,%i\r\n", getId(),
                     (const char *) conf->sectors[ (int) getTerrain() ].desc,
	    (const char *) region->getName(),
        getX(), getY(), getZ());
    send_to_user(" %s\r\n", (const char *) getName() );

    line[0] = 0;
    pos = 0;

    if (!(proxy->isMudEmulation() && conf->getBriefMode() ) ) {
        QByteArray desc = getDesc();

        for (i = 0; i <= strlen(desc); i++)
            if (desc[i] == '|') {
                line[pos] = 0;
                send_to_user("%s\r\n", line);
                line[0] = 0;
                pos = 0;
            } else {
                line[pos++] = desc[i];
            }
    }
    send_to_user(" note: %s\r\n", (const char *) getNote());

    
    sprintf(line, "Doors:");
    for (i = 0; i <= 5; i++) {
        ExitDirection iDir = static_cast<ExitDirection>(i);
      if (isDoorSecret(iDir)) {
        sprintf(line + strlen(line), " %c: %s", dirbynum(iDir), (const char *) getDoor(iDir));
      }
    
    }
    send_to_user("%s\r\n", line);

    
    if (conf->getBriefMode() && proxy->isMudEmulation()) {
      sprintf(line, "Exits: ");
      for (i = 0; i <= 5; i++) {
          ExitDirection iDir = static_cast<ExitDirection>(i);
          if (isExitPresent(iDir) == true) {
              if ( isExitUndefined(iDir) ) {
                  sprintf(line + strlen(line), " #%s#", exitnames[i]);
                  continue;
              }
              if ( isExitDeath(iDir) ) {
                  sprintf(line + strlen(line), " !%s!", exitnames[i]);
                  continue;
              }

              if (isDoorSet(iDir)) {
                  if (isDoorSecret(iDir) == false)  {
                      sprintf(line + strlen(line), " (%s)", exitnames[i]);
                  } else {
                      sprintf(line + strlen(line), " +%s+", exitnames[i]);
                  }
              } else {
                  sprintf(line + strlen(line), " %s", exitnames[i]);
              }
          }
      }
      
      
    } else {
      
      line[0] = 0;
      sprintf(line, " exits:");
  
      for (i = 0; i <= 5; i++) {
          ExitDirection iDir = static_cast<ExitDirection>(i);
          if (isExitPresent(iDir) == true) {
              if (isExitUndefined(iDir) ) {
                  sprintf(line + strlen(line), " #%s#", exitnames[i]);
                  continue;
              }
              if (isExitDeath(iDir)) {
                  sprintf(line + strlen(line), " !%s!", exitnames[i]);
                  continue;
              }

              if (isDoorSet(iDir)) {
                  if (isDoorSecret(iDir) == false)  {
                      sprintf(line + strlen(line), " (%s)", exitnames[i]);
                  } else {
                      sprintf(line + strlen(line), " +%s+", exitnames[i]);
                  }
              } else {
                  sprintf(line + strlen(line), " %s", exitnames[i]);
              }

              sprintf(line + strlen(line), " -[to %i]-", getExitLeadsTo(iDir) );
          }
       }

    }

    send_to_user("%s\r\n", line);
}
コード例 #22
0
ファイル: aservelib.cpp プロジェクト: tommymitch/Aserve
int aserveGetVelocity(void)
{
	MidiMsg note = getNote();		
	return note.databyte2;
}
コード例 #23
0
void PurchaseEditor::doPurchase()
{
    if (!db.isOpen()) db.open();
    if (!db.isOpen()) {return;}

    QStringList items;
    items.clear();

    //temporal items list
    items.append("empty list"); //just a tweak for creating the transaction, cleaning after creating it.

    Azahar *myDb = new Azahar;
    myDb->setDatabase(db);

    qDebug()<<"doPurchase...";
    qDebug()<<"DATE:"<<getDate().toString()<<getTime().toString();

    TransactionInfo tInfo;
    if (getPurchased()) {
        tInfo.type    = tBuy;
    } else {
        tInfo.type    = tDonation;
    }
    tInfo.amount  = getTotalBuy();
    tInfo.date    = getDate();
    tInfo.time    = getTime();
    tInfo.paywith = 0.0;
    tInfo.changegiven = 0.0;
    tInfo.paymethod   = pCash;
    tInfo.state   = tCompleted;
    tInfo.userid  = loggedUserId;
    tInfo.clientid= 0;
    tInfo.cardnumber  = "-NA-";
    tInfo.cardauthnum = "-NA-";
    tInfo.itemcount   = getItemCount();
    tInfo.itemlist    = items.join(";");
    tInfo.utility     = 0; //FIXME: utility is calculated until products are sold, not before.
    tInfo.terminalnum = 0; //NOTE: Not really a terminal... from admin computer.
    tInfo.providerid  = 1; //FIXME!
    tInfo.specialOrders = "";
    tInfo.balanceId = 0;
    tInfo.donor       = getDonor();
    tInfo.note= getNote();
    qulonglong trnum = myDb->insertTransaction(tInfo); //to get the transaction number to insert in the log.
    if ( trnum <= 0 ) {
        qDebug()<<"ERROR: Could not create a Purchase Transaction ::doPurchase()";
        qDebug()<<"Error:"<<myDb->lastError();
        //TODO: Notify the user about the error.
    }
    //Now cleaning the items to fill with real items...
    items.clear();
    //assigning new transaction id to the tInfo.
    tInfo.id = trnum;

    QHash<QString, ProductInfo> hash = getHash();
    ProductInfo info;
    TransactionItemInfo tItemInfo;
    //Iterate the hash
    QHashIterator<QString, ProductInfo> i(hash);
    int j=-1;
    while (i.hasNext()) {
        j+=1;
        i.next();
        info = i.value();
        double oldstockqty = info.stockqty;
        info.stockqty = info.purchaseQty+oldstockqty;
        //Modify data on mysql...
        //validDiscount is for checking if product already exists on db. see line # 396 of purchaseeditor.cpp
        if (info.validDiscount) {
            if (!myDb->updateProduct(info, info.code))
                qDebug()<<myDb->lastError();
            else {
                //FIXME: loggedUserId, logging in widgets!?
                myDb->insertLog(loggedUserId, QDate::currentDate(), QTime::currentTime(), "[PURCHASE] "+i18n("Purchase #%4 - %1 x %2 (%3)", info.purchaseQty, info.desc, info.code, trnum));
                qDebug()<<"Product updated [purchase] ok..."<<i18n("Purchase #%4 - %1 x %2 (%3)", info.purchaseQty, info.desc, info.code, trnum);
            }

        } else {
            if (!myDb->insertProduct(info))
                qDebug()<<myDb->lastError();
            else {
                myDb->insertLog(loggedUserId, QDate::currentDate(), QTime::currentTime(), "[PURCHASE] "+i18n("Purchase #%4 - [new] - %1 x %2 (%3)", info.purchaseQty, info.desc, info.code, trnum) );
                qDebug()<<i18n("Purchase #%4 - [new] - %1 x %2 (%3)", info.purchaseQty, info.desc, info.code, trnum);
            }
        }

        ui->p->m_model->select();
        items.append(info.code+"/"+QString::number(info.purchaseQty));

        // Compiling transactionitems
        tItemInfo.transactionid   = tInfo.id;
        tItemInfo.position        = j;
        tItemInfo.productCode     = i.key();
        tItemInfo.unitStr         = info.unitStr;
        tItemInfo.qty             = info.purchaseQty;
        tItemInfo.cost            = info.cost;
        tItemInfo.price           = info.price;
        tItemInfo.disc            = info.disc * info.purchaseQty;
        tItemInfo.total           = info.cost * info.purchaseQty;
        tItemInfo.completePayment = true;
        if (info.isAGroup)
          tItemInfo.name            = info.desc.replace("\n", "|");
        else
          tItemInfo.name            = info.desc;
        tItemInfo.isGroup = info.isAGroup;
        myDb->insertTransactionItem(tItemInfo);
    }
    //update items in transaction data
    tInfo.itemlist = items.join(";");
    myDb->updateTransaction(tInfo);
    delete myDb;
}
コード例 #24
0
ファイル: main.cpp プロジェクト: da-woods/sousaphone-hero
int main(int argc, char *argv[]) try
{
   setPath(argv[0]);
   
   bool shaders = true;
   
   // load tune if argument is given
   for (int i=1; i<argc; ++i)
   {
      const std::string arg = argv[i];
      if (arg == "--no-shaders")
         shaders = false;
      else
         loadTune(arg);
   }

   class InitAndQuit
   {
      public:
         InitAndQuit(bool shadersOn)
         {
            if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
            {
               std::ostringstream error;
               error << "Failed on SDL_Init: " << SDL_GetError() << "\n";
               throw std::runtime_error(error.str());
            }
            graphics::setupGraphics(shadersOn);
            SDL_WM_SetCaption("Sousaphone Hero", "Sousaphone Hero");
            if(Mix_OpenAudio(AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS) != 0)
            {
               SDL_Quit();
               std::ostringstream error;
               error << "Failed on Mix_OpenAudio: " << Mix_GetError() << "\n";
               throw std::runtime_error(error.str());
            }

            std::srand(time(NULL));

            Mix_ChannelFinished(doChangedNotes); // set callback function

            startTiming();
         }

         ~InitAndQuit()
         {
            graphics::cleanupGraphics();
            Mix_CloseAudio();
            SDL_Quit();
         }
   } iandq(shaders);

   // load all the notes (to load them)
   getNoteA(); getNoteB(); getNoteC(); getNoteD(); getNoteE(); getNoteF(); getNoteG();

   const bool demoMode = false;

   double lastNoteFraction = 0;

   int channel = -1;

   bool tuneStarted = false;

   try
   {
      while(1)
      {
         const double currentNoteFraction = noteFraction();
         if (currentNoteFraction < lastNoteFraction) // i.e. we have wrapped round a note
         {
            incrementTune();
            if (demoMode)
            {
               const char current = getCurrentNote();
               if (current != NO_NOTE_CHARACTER)
               {
                  if (channel != -1)
                     Mix_HaltChannel(channel);

                  channel = Mix_PlayChannelTimed(-1, getNote(current).get(), -1, NOTE_DURATION);
               }
            }
         }
         lastNoteFraction = currentNoteFraction;

         if ((getTimeSinceStart() > graphics::ZOOM_OUT_LENGTH*1000.0) && !tuneStarted)
         {
            startTune();
            tuneStarted = true;
         }

         //SDL_Delay(100);

         doIOLoop();
         playAppropriateNote();
         graphics::draw(currentNoteFraction);
         graphics::updateScreen();
         score::doEveryLoop();
      }
   }
   catch(QuitSignal&)
   {} // do nothing

   return 0;
} catch (std::exception& error)
{
   std::cout << error.what();
   return 1;
}
コード例 #25
0
ファイル: Card.cpp プロジェクト: AirBayCreative/GameCards
String Card::getAll() {
	String all = getQuantity()+delim+getText()+delim+getThumb()+delim+getFront()+
			delim+getBack()+delim+getId()+delim+getRate()+delim+getValue()+delim+getNote()+delim;
	return all;
}