//--------------------------------------------------------------------------------------- void DlgMetronome::on_button(wxCommandEvent& event) { int button = event.GetId(); if (button == k_id_button_increment) { increment_tempo(); display_tempo(); } else if (button == k_id_button_decrement) { decrement_tempo(); display_tempo(); } else if (button == k_id_button_tap_tempo) { compute_tapped_tempo(); display_tempo(); } else if (button == k_id_button_start) { if (m_pMtr->is_running()) { m_pMtr->stop(); m_pStartButton->SetLabel(_("Start")); } else { m_pMtr->start(); m_pStartButton->SetLabel(_("Stop")); } } return; }
int main(int argc, char** argv) { if (argc != 3) { printf("usage: %s device key\n", argv[0]); printf(" device: /dev/midi\n"); printf(" key: 36\n"); printf(" -1 for key means display mode\n"); exit(1); } int key = atoi(argv[2]); int display_mode = key == -1; if (!display_mode && (key < 0 || key > 127)) { printf("key must be between 0 and 127. The dtx500 kick drum is 36\n"); exit(1); } int fd = open(argv[1], O_RDONLY); if (fd == -1) { perror("tempo: open"); exit(1); } int state = INITIAL; double ts[SAMPLES]; int pos = 0; unsigned char c; while (1) { read(fd, &c, 1); if (state == INITIAL) { if (c >= 0x90 && c < 0xA0) { state = SAW_NOTE_ON; } } else if (state == SAW_NOTE_ON) { if (display_mode) { printf(" %d\n", c); } else if (c == key) { ts[pos % SAMPLES] = current_minute(); if (pos > SAMPLES) { int tempo = (SAMPLES-1)/( ts[pos % SAMPLES] - ts[(pos+1) % SAMPLES]) + 0.5; display_tempo(tempo); } pos++; } state = INITIAL; } } }
//--------------------------------------------------------------------------------------- void DlgMetronome::on_update_number(wxCommandEvent& WXUNUSED(event)) { wxString value = m_pTempoDisplay->GetValue(); long num = 0L; if (value.ToLong(&num)) { m_tempo = num; if (m_tempo < 1) m_tempo = 1; else if (m_tempo > 300) m_tempo = 300; } set_tempo(m_tempo); display_tempo(); }
//--------------------------------------------------------------------------------------- void DlgMetronome::on_tempo_slider(wxCommandEvent& WXUNUSED(event)) { set_tempo( m_pTempoSlider->GetValue() ); display_tempo(); }
//--------------------------------------------------------------------------------------- void DlgMetronome::on_tempo_choice(wxCommandEvent& event) { int i = m_pItalianTempo->GetSelection(); set_tempo( m_tempi[i].defaultTempo ); display_tempo(); }