📄 nyquist.cpp
字号:
nyx_capture_output(65536); nyx_set_input_audio(StaticGetCallback, (void *)this, mCurNumChannels, mCurLen, mCurTrack[0]->GetRate()); wxString cmd; if (mDebug) { cmd = cmd + wxT("(setf *tracenable* T)\n"); } for(unsigned int j=0; j<mControls.GetCount(); j++) { if (mControls[j].type==NYQ_CTRL_REAL) cmd = cmd+wxString::Format(wxT("(setf %s %f)\n"), mControls[j].var.c_str(), mControls[j].val); else if (mControls[j].type==NYQ_CTRL_INT) cmd = cmd+wxString::Format(wxT("(setf %s %d)\n"), mControls[j].var.c_str(), (int)(mControls[j].val)); else if (mControls[j].type==NYQ_CTRL_STRING) { wxString str = mControls[j].valStr; str.Replace(wxT("\""), wxT("'")); cmd = cmd+wxString::Format(wxT("(setf %s \"%s\")\n"), mControls[j].var.c_str(), str.c_str()); } } cmd += mCmd; //wxMessageBox(cmd); int i; for (i = 0; i < mCurNumChannels; i++) mCurBuffer[i] = NULL; rval = nyx_eval_expression(cmd.mb_str()); if (mDebug) { int len; const char *str; nyx_get_captured_output(&len, &str); mDebugOutput += wxString(str, wxConvISO8859_1, len); } if (rval == nyx_string) { wxMessageBox(wxString(nyx_get_string(), wxConvISO8859_1), wxT("Nyquist"), wxOK | wxCENTRE, mParent); nyx_cleanup(); setlocale(LC_NUMERIC, ""); return true; } if (rval == nyx_double) { wxString str; str.Printf(_("Nyquist returned the value: %f"), nyx_get_double()); wxMessageBox(str, wxT("Nyquist"), wxOK | wxCENTRE, mParent); nyx_cleanup(); setlocale(LC_NUMERIC, ""); return true; } if (rval == nyx_int) { wxString str; str.Printf(_("Nyquist returned the value: %d"), nyx_get_int()); wxMessageBox(str, wxT("Nyquist"), wxOK | wxCENTRE, mParent); nyx_cleanup(); setlocale(LC_NUMERIC, ""); return true; } if (rval == nyx_labels) { int numLabels = nyx_get_num_labels(); int l; LabelTrack *ltrack = NULL; TrackListIterator iter(mTracks); Track *t = iter.First(); while(t && !ltrack) { if (t->GetKind() == Track::Label) ltrack = (LabelTrack *)t; t = iter.Next(); } if (!ltrack) { ltrack = mFactory->NewLabelTrack(); mTracks->Add((Track *)ltrack); } for(l=0; l<numLabels; l++) { double t; const char *str; nyx_get_label(l, &t, &str); ltrack->AddLabel(t + mT0, t + mT0, LAT1CTOWX(str)); } nyx_cleanup(); setlocale(LC_NUMERIC, ""); return true; } if (rval != nyx_audio) { wxMessageBox(_("Nyquist did not return audio.\n"), wxT("Nyquist"), wxOK | wxCENTRE, mParent); nyx_cleanup(); setlocale(LC_NUMERIC, ""); return false; } int outChannels; outChannels = nyx_get_audio_num_channels(); if (outChannels > mCurNumChannels) { wxMessageBox(_("Nyquist returned too many audio channels.\n"), wxT("Nyquist"), wxOK | wxCENTRE, mParent); nyx_cleanup(); setlocale(LC_NUMERIC, ""); return false; } double rate = mCurTrack[0]->GetRate(); for(i=0; i<outChannels; i++) { sampleFormat format = mCurTrack[i]->GetSampleFormat(); mOutputTrack[i] = mFactory->NewWaveTrack(format); if (outChannels == mCurNumChannels) rate = mCurTrack[i]->GetRate(); mOutputTrack[i]->SetRate( rate ); mCurBuffer[i] = NULL; } nyx_get_audio(StaticPutCallback, (void *)this); for(i=0; i<outChannels; i++) { mOutputTrack[i]->Flush(); if (mCurBuffer[i]) DeleteSamples(mCurBuffer[i]); mOutputTime = mOutputTrack[i]->GetEndTime(); } for(i=0; i<mCurNumChannels; i++) { WaveTrack *out; if (outChannels == mCurNumChannels) out = mOutputTrack[i]; else out = mOutputTrack[0]; mCurTrack[i]->Clear(mT0, mT1); mCurTrack[i]->Paste(mT0, out); } for(i=0; i<outChannels; i++) delete mOutputTrack[i]; nyx_cleanup(); // Reset locale setlocale(LC_NUMERIC, ""); return true;}/**********************************************************/#define ID_NYQ_SLIDER 2000#define ID_NYQ_TEXT 3000BEGIN_EVENT_TABLE(NyquistDialog, wxDialog) EVT_BUTTON(wxID_OK, NyquistDialog::OnOk) EVT_BUTTON(wxID_CANCEL, NyquistDialog::OnCancel) EVT_BUTTON(wxID_MORE, NyquistDialog::OnDebug) EVT_COMMAND_RANGE(ID_NYQ_SLIDER, ID_NYQ_SLIDER+99, wxEVT_COMMAND_SLIDER_UPDATED, NyquistDialog::OnSlider) EVT_COMMAND_RANGE(ID_NYQ_TEXT, ID_NYQ_TEXT+99, wxEVT_COMMAND_TEXT_UPDATED, NyquistDialog::OnText)END_EVENT_TABLE()NyquistDialog::NyquistDialog(wxWindow * parent, wxWindowID id, const wxString & title, wxString info, NyqControlArray *controlArray) :wxDialog(parent, id, title){ mControls = controlArray; mInHandler = true; // prevents race condition on MSW wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hSizer; wxButton *button; if (info.Length() > 0) { wxControl *item; item = new wxStaticText(this, -1, info); mainSizer->Add(item, 0, wxALIGN_LEFT | wxALL, 5); } wxFlexGridSizer *grid = new wxFlexGridSizer(4, 0, 0); for(unsigned int i=0; i<mControls->GetCount(); i++) { wxControl *item; NyqControl *ctrl = &((*mControls)[i]); int val = (int)(0.5 + ctrl->ticks * (ctrl->val - ctrl->low)/ (ctrl->high - ctrl->low)); item = new wxStaticText(this, -1, ctrl->name); grid->Add(item, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxALL, 5); if (ctrl->type == NYQ_CTRL_STRING) { grid->Add(10, 10); item = new wxTextCtrl(this, ID_NYQ_TEXT+i, ctrl->valStr, wxDefaultPosition, wxSize(150, -1)); grid->Add(item, 0, wxALIGN_CENTRE | wxALIGN_CENTER_VERTICAL | wxALL, 5); } else { // Integer or Real item = new wxTextCtrl(this, ID_NYQ_TEXT+i, wxT(""), wxDefaultPosition, wxSize(60, -1)); grid->Add(item, 0, wxALIGN_CENTRE | wxALIGN_CENTER_VERTICAL | wxALL, 5); item = new wxSlider(this, ID_NYQ_SLIDER+i, val, 0, ctrl->ticks, wxDefaultPosition, wxSize(150, -1)); grid->Add(item, 0, wxALIGN_CENTRE | wxALIGN_CENTER_VERTICAL | wxALL, 5); } item = new wxStaticText(this, -1, ctrl->label); grid->Add(item, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5); } mainSizer->Add(grid, 0, wxALIGN_CENTRE | wxALL, 5); hSizer = new wxBoxSizer(wxHORIZONTAL); button = new wxButton(this, wxID_CANCEL, _("Cancel")); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_MORE, _("Debug")); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_OK, _("OK")); button->SetDefault(); button->SetFocus(); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); mainSizer->Add(hSizer, 0, wxALIGN_CENTRE | wxALL, 5); mInHandler = false; wxCommandEvent dummy; OnSlider(dummy); SetAutoLayout(true); SetSizer(mainSizer); mainSizer->Fit(this); mainSizer->SetSizeHints(this);}void NyquistDialog::OnSlider(wxCommandEvent & /* event */){ if (mInHandler) return; // prevent recursing forever mInHandler = true; for(unsigned int i=0; i<mControls->GetCount(); i++) { NyqControl *ctrl = &((*mControls)[i]); if (ctrl->type == NYQ_CTRL_STRING) continue; wxSlider *slider = (wxSlider *)FindWindow(ID_NYQ_SLIDER + i); wxTextCtrl *text = (wxTextCtrl *)FindWindow(ID_NYQ_TEXT + i); wxASSERT(slider && text); int val = slider->GetValue(); ctrl->val = (val / (double)ctrl->ticks)* (ctrl->high - ctrl->low) + ctrl->low; wxString valStr; if (ctrl->type == NYQ_CTRL_REAL) { if (ctrl->high - ctrl->low < 1) valStr.Printf(wxT("%.3f"), ctrl->val); else if (ctrl->high - ctrl->low < 10) valStr.Printf(wxT("%.2f"), ctrl->val); else if (ctrl->high - ctrl->low < 100) valStr.Printf(wxT("%.1f"), ctrl->val); else valStr.Printf(wxT("%d"), (int)floor(ctrl->val + 0.5)); } else if (ctrl->type == NYQ_CTRL_INT) valStr.Printf(wxT("%d"), (int)floor(ctrl->val + 0.5)); if (valStr != wxT("")) text->SetValue(valStr); } mInHandler = false;}void NyquistDialog::OnText(wxCommandEvent & /* event */){ if (mInHandler) return; // prevent recursing forever mInHandler = true; for(unsigned int i=0; i<mControls->GetCount(); i++) { NyqControl *ctrl = &((*mControls)[i]); wxTextCtrl *text = (wxTextCtrl *)FindWindow(ID_NYQ_TEXT + i); wxASSERT(text); ctrl->valStr = text->GetValue(); if (ctrl->type == NYQ_CTRL_STRING) continue; wxSlider *slider = (wxSlider *)FindWindow(ID_NYQ_SLIDER + i); wxASSERT(slider); ctrl->valStr.ToDouble(&ctrl->val); int pos = (int)floor((ctrl->val - ctrl->low) / (ctrl->high - ctrl->low) * ctrl->ticks + 0.5); if (pos < 0) pos = 0; if (pos > ctrl->ticks) pos = ctrl->ticks; slider->SetValue(pos); } mInHandler = false; }void NyquistDialog::OnOk(wxCommandEvent & /* event */){ // Transfer data EndModal(wxID_OK);}void NyquistDialog::OnCancel(wxCommandEvent & /* event */){ EndModal(wxID_CANCEL);}void NyquistDialog::OnDebug(wxCommandEvent & /* event */){ // Transfer data EndModal(wxID_MORE);}/**********************************************************/BEGIN_EVENT_TABLE(NyquistInputDialog, wxDialog) EVT_BUTTON(wxID_OK, NyquistInputDialog::OnOk) EVT_BUTTON(wxID_CANCEL, NyquistInputDialog::OnCancel) EVT_BUTTON(wxID_MORE, NyquistInputDialog::OnDebug)END_EVENT_TABLE()NyquistInputDialog::NyquistInputDialog(wxWindow * parent, wxWindowID id, const wxString & title, const wxString & prompt, wxString initialCommand) :wxDialog(parent, id, title){ wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hSizer; wxButton *button; wxControl *item; item = new wxStaticText(this, -1, prompt); mainSizer->Add(item, 0, wxALIGN_LEFT | wxLEFT | wxTOP | wxRIGHT, 10); mCommandText = new wxTextCtrl(this, -1, initialCommand, wxDefaultPosition, wxSize(400, 200), wxTE_MULTILINE); mainSizer->Add(mCommandText, 0, wxALIGN_LEFT | wxALL, 10); hSizer = new wxBoxSizer(wxHORIZONTAL); button = new wxButton(this, wxID_CANCEL, _("Cancel")); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_MORE, _("Debug")); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); button = new wxButton(this, wxID_OK, _("OK")); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); mainSizer->Add(hSizer, 0, wxALIGN_CENTRE | wxLEFT | wxBOTTOM | wxRIGHT, 5); SetAutoLayout(true); SetSizer(mainSizer); mainSizer->Fit(this); mainSizer->SetSizeHints(this); mCommandText->SetFocus();}wxString NyquistInputDialog::GetCommand(){ return mCommandText->GetValue();}void NyquistInputDialog::OnOk(wxCommandEvent & /* event */){ EndModal(wxID_OK);}void NyquistInputDialog::OnCancel(wxCommandEvent & /* event */){ EndModal(wxID_CANCEL);}void NyquistInputDialog::OnDebug(wxCommandEvent & /* event */){ // Transfer data EndModal(wxID_MORE);}/**********************************************************/BEGIN_EVENT_TABLE(NyquistOutputDialog, wxDialog) EVT_BUTTON(wxID_OK, NyquistOutputDialog::OnOk)END_EVENT_TABLE()NyquistOutputDialog::NyquistOutputDialog(wxWindow * parent, wxWindowID id, const wxString & title, const wxString & prompt, wxString message) :wxDialog(parent, id, title){ wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hSizer; wxButton *button; wxControl *item; item = new wxStaticText(this, -1, prompt); mainSizer->Add(item, 0, wxALIGN_LEFT | wxLEFT | wxTOP | wxRIGHT, 10); item = new wxTextCtrl(this, -1, message, wxDefaultPosition, wxSize(400, 200), wxTE_MULTILINE | wxTE_READONLY); mainSizer->Add(item, 0, wxALIGN_LEFT | wxALL, 10); hSizer = new wxBoxSizer(wxHORIZONTAL); button = new wxButton(this, wxID_OK, _("OK")); button->SetDefault(); button->SetFocus(); hSizer->Add(button, 0, wxALIGN_CENTRE | wxALL, 5); mainSizer->Add(hSizer, 0, wxALIGN_CENTRE | wxLEFT | wxBOTTOM | wxRIGHT, 5); SetAutoLayout(true); SetSizer(mainSizer); mainSizer->Fit(this); mainSizer->SetSizeHints(this);}void NyquistOutputDialog::OnOk(wxCommandEvent & /* event */){ EndModal(wxID_OK);}// Indentation settings for Vim and Emacs and unique identifier for Arch, a// version control system. Please do not modify past this point.//// Local Variables:// c-basic-offset: 3// indent-tabs-mode: nil// End://// vim: et sts=3 sw=3// arch-tag: a6e418bb-2609-42f2-a8ae-8e50373855f3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -