void select_menu(){ // menu int menu; char command[1024]; printf("- Select Menu -\n"); printf("1. create note\n"); printf("2. write note\n"); printf("3. read note\n"); printf("4. delete note\n"); printf("5. exit\n"); scanf("%d", &menu); clear_newlines(); switch(menu){ case 1: create_note(); break; case 2: write_note(); break; case 3: read_note(); break; case 4: delete_note(); break;6 case 5: printf("bye\n"); return; case 0x31337: printf("welcome to hacker's secret menu\n"); printf("i'm sure 1byte overflow will be enough for you to pwn this\n"); fgets(command, 1025, stdin); break; default: printf("invalid menu\n"); break; } select_menu(); }
bool NoteDirectoryWatcherApplicationAddin::handle_timeout() { m_lock.lock(); try { std::vector<Glib::ustring> keysToRemove(m_file_change_records.size()); for(auto iter : m_file_change_records) { DBG_OUT("NoteDirectoryWatcher: Handling (timeout) %s", iter.first.c_str()); // Check that Note.Saved event didn't occur within (check-interval -2) seconds of last write if(m_note_save_times.find(iter.first) != m_note_save_times.end() && std::abs((m_note_save_times[iter.first] - iter.second.last_change).total_seconds()) <= (m_check_interval - 2)) { DBG_OUT("NoteDirectoryWatcher: Ignoring (timeout) because it was probably a Gnote write"); keysToRemove.push_back(iter.first); continue; } // TODO: Take some actions to clear note_save_times? Not a large structure... sharp::DateTime last_change(iter.second.last_change); if(sharp::DateTime::now() > last_change.add_seconds(4)) { if(iter.second.deleted) { delete_note(iter.first); } else { add_or_update_note(iter.first); } keysToRemove.push_back(iter.first); } } for(auto note_id : keysToRemove) { m_file_change_records.erase(note_id); } } catch(...) {} m_lock.unlock(); return false; }
VideoEditor::VideoEditor(NotesModule::Video* vid ,QWidget *parent) :QWidget(parent), ui(new Ui::VideoEditor), video(vid) { ui->setupUi(this); ui->videoPlayer->setMinimumHeight(170); ui->volumeSlider->setAudioOutput(ui->videoPlayer->audioOutput()); ui->volumeSlider->setEnabled(false); ui->pushButtonDelete->setEnabled(false); if (video){ ui->lineEditTitle->setText(dynamic_cast<NotesModule::Note*>(video)->getTitle()); ui->textEditDescription->setText(dynamic_cast<NotesModule::Multimedia*>(video)->getDescription()); } QObject::connect(ui->pushButtonSave,SIGNAL(clicked()),this,SLOT(saveVideo())); QObject::connect(ui->lineEditTitle,SIGNAL(textEdited(QString)),this,SLOT(activateSave(QString))); QObject::connect(ui->textEditDescription,SIGNAL(textChanged()),this,SLOT(activateSave())); QObject::connect(ui->pushButtonBrowse,SIGNAL(clicked()),this,SLOT(getVideoPath())); QObject::connect(ui->pushButtonPlay,SIGNAL(clicked()),this,SLOT(playVideo())); QObject::connect(ui->pushButtonStop,SIGNAL(clicked()),this,SLOT(stopVideo())); QObject::connect(ui->pushButtonPause,SIGNAL(clicked()),this,SLOT(pauseVideo())); QObject::connect(ui->pushButtonDelete,SIGNAL(clicked()),this,SLOT(delete_note())); }
void MIDI_parser(uint8_t* MIDI_buffer, uint8_t nb_MIDI_bytes) { static uint8_t index = 0; static uint8_t state = 0; static uint8_t MIDI_note, MIDI_velocity; static uint8_t MIDI_CC_number, MIDI_CC_value; static uint8_t MIDI_PB_byte1, MIDI_PB_byte2; uint8_t MIDI_byte; uint16_t PB_wheel; // Process message while (nb_MIDI_bytes != 0) { // Read a new byte from the MIDI buffer MIDI_byte = MIDI_buffer[index]; // Move to next byte if(MIDI_byte == 0xf8 || MIDI_byte == 0xfe ) { if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; continue; }//else{ // printf ("0x%x @index = %d\n", MIDI_byte, index); //} switch (state) { // State 0 = Starting point for a new MIDI message case 0 : { switch (MIDI_byte & 0xF0) { case 0x90 : // Note ON message { state = 10; // Next state is 10 // printf ("note ON event\n"); if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; break; } case 0x80 : // Note OFF message { state = 20; // Next state is 20 //printf ("note OFF event\n"); if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; break; } case 0xB0 : // CC message { state = 30; // Next state is 30 //printf ("CC event\n"); if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; break; } case 0xE0 : // Pitch Bend message { state = 40; // Next state is 40 // printf ("PB event\n"); if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; break; } default : // Other type of message, move to next byte but stays in state 0 { if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; break; } } break; } // State 10 & 11 : Note ON command case 10 : { if (MIDI_byte>0x7F) // If the following byte is not a note number { state = 0; // Return to state 0 without moving to next byte } else { MIDI_note = MIDI_byte; // Save MIDI note if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 11; // Next state is 11 } break; } case 11 : { MIDI_velocity = MIDI_byte; // Save MIDI velocity if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 10; // Next state is 10 if (MIDI_velocity > 0) { printf ("Note ON : %d %d\n", MIDI_note, MIDI_velocity); note_list = add_note_last(note_list, MIDI_note, MIDI_velocity); new_note_event = 1; } else { printf ("Note OFF 1: %d %d\n", MIDI_note, MIDI_velocity); note_list = delete_note(note_list, MIDI_note); } break; } // State 20 & 21 : Note OFF command case 20 : { if (MIDI_byte>0x7F) // If the following byte is not a note number { state = 0; // Return to state 0 without moving to next byte } else { MIDI_note = MIDI_byte; // Save MIDI note if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 21; // Next state is 21 } break; } case 21 : { MIDI_velocity = MIDI_byte; // Save MIDI velocity if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 20; // Next state is 20 printf ("Note OFF 2: %d %d\n", MIDI_note, MIDI_velocity); note_list = delete_note(note_list, MIDI_note); break; } // State 30 & 31 : CC command case 30 : { if (MIDI_byte>0x7F) // If the following byte is not a CC number { state = 0; // Return to state 0 without moving to next byte } else { MIDI_CC_number = MIDI_byte; // Save MIDI CC number if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 31; // Next state is 31 } break; } case 31 : { MIDI_CC_value = MIDI_byte; // Save MIDI velocity if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 30; // Next state is 30 printf ("CC : %d %d\n", MIDI_CC_number, MIDI_CC_value); // ChangeParam(MIDI_CC_number, MIDI_CC_value); break; } // State 40 & 41 : Pitch Bend message case 40 : { if (MIDI_byte > 0x7F) // If following byte is note a PB value { state = 0; // Return to state 0 } else { MIDI_PB_byte1 = MIDI_byte; // Save MIDI CC number if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; state = 41; // Next state is 41 } break; } case 41 : { MIDI_PB_byte2 = MIDI_byte; // Save MIDI velocity if (index == (MIDI_BUFFER_LENGTH-1)) index = 0; // Move to next MIDI byte else index ++; nb_MIDI_bytes--; PB_wheel = (uint8_t) MIDI_PB_byte2; PB_wheel <<=7; PB_wheel |= (uint8_t) MIDI_PB_byte1; printf ("PB : %x\n", PB_wheel); //params.bend = params.pitch * 2.0f * ( (float_t)PB_wheel - 8192.0f) / (4096.0f * 12.0f); state = 40; // Next state is 00 break; } } } }