Placeholder Edit->Sort menu entry and disabled audio scrubbing again

Originally committed to SVN as r466.
This commit is contained in:
Rodrigo Braz Monteiro 2006-07-06 22:39:58 +00:00
parent 88016e0602
commit 8f077dc4ee
5 changed files with 69 additions and 46 deletions

View file

@ -1210,7 +1210,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
} }
// Stop scrubbing // Stop scrubbing
bool scrubButton = event.ButtonIsDown(wxMOUSE_BTN_MIDDLE); bool scrubButton = false && event.ButtonIsDown(wxMOUSE_BTN_MIDDLE);
if (scrubbing && !scrubButton) { if (scrubbing && !scrubButton) {
// Release mouse // Release mouse
scrubbing = false; scrubbing = false;
@ -1237,66 +1237,77 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event) {
// Set variables // Set variables
scrubLastPos = GetSampleAtX(x); scrubLastPos = GetSampleAtX(x);
scrubTime = clock(); scrubTime = clock();
scrubLastRate = provider->GetSampleRate();
} }
// Scrub // Scrub
if (scrubbing && scrubButton) { if (scrubbing && scrubButton) {
// Get current data // Get current data
__int64 curScrubPos = MAX(0,GetSampleAtX(x)); __int64 exactPos = MAX(0,GetSampleAtX(x));
__int64 scrubDelta = curScrubPos - scrubLastPos;
int curScrubTime = clock(); int curScrubTime = clock();
int scrubDeltaTime = curScrubTime - scrubTime; int scrubDeltaTime = curScrubTime - scrubTime;
bool invert = exactPos < scrubLastPos;
__int64 curScrubPos = exactPos;
// Copy data to buffer if (scrubDeltaTime > 0) {
if (scrubDelta != 0 && scrubDeltaTime > 0) { // Get derived data
// Create buffer int rateChange = provider->GetSampleRate()/20;
int bufSize = scrubDeltaTime * scrubProvider->GetSampleRate() / CLK_TCK; int curRate = MID(int(scrubLastRate-rateChange),abs(int(exactPos - scrubLastPos)) * CLK_TCK / scrubDeltaTime,int(scrubLastRate+rateChange));
short *buf = new short[bufSize]; if (abs(curRate-scrubLastRate) < rateChange) curRate = scrubLastRate;
curScrubPos = scrubLastPos + (curRate * scrubDeltaTime / CLK_TCK * (invert ? -1 : 1));
__int64 scrubDelta = curScrubPos - scrubLastPos;
scrubLastRate = curRate;
// Flag as inverted, if necessary // Copy data to buffer
bool invert = scrubDelta < 0; if (scrubDelta != 0) {
if (invert) scrubDelta = -scrubDelta; // Create buffer
int bufSize = scrubDeltaTime * scrubProvider->GetSampleRate() / CLK_TCK;
short *buf = new short[bufSize];
// Copy data from original provider to temp buffer // Flag as inverted, if necessary
short *temp = new short[scrubDelta]; if (invert) scrubDelta = -scrubDelta;
provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),scrubDelta);
// Scale // Copy data from original provider to temp buffer
float scale = float(double(scrubDelta) / double(bufSize)); short *temp = new short[scrubDelta];
float start,end; provider->GetAudio(temp,MIN(curScrubPos,scrubLastPos),scrubDelta);
int istart,iend;
float tempfinal; // Scale
for (int i=0;i<bufSize;i++) { float scale = float(double(scrubDelta) / double(bufSize));
start = i*scale; float start,end;
end = (i+1)*scale; int istart,iend;
istart = (int) start; float tempfinal;
iend = MIN((int) end,scrubDelta-1); for (int i=0;i<bufSize;i++) {
if (istart == iend) tempfinal = temp[istart] * (end - start); start = i*scale;
else { end = (i+1)*scale;
tempfinal = temp[istart] * (1 + istart - start) + temp[iend] * (end - iend); istart = (int) start;
for (int j=istart+1;j<iend;j++) tempfinal += temp[i]; iend = MIN((int) end,scrubDelta-1);
if (istart == iend) tempfinal = temp[istart] * (end - start);
else {
tempfinal = temp[istart] * (1 + istart - start) + temp[iend] * (end - iend);
for (int j=istart+1;j<iend;j++) tempfinal += temp[i];
}
buf[i] = tempfinal / scale;
} }
buf[i] = tempfinal / scale; //int len = MIN(bufSize,scrubDelta);
} //for (int i=0;i<len;i++) buf[i] = temp[i];
//int len = MIN(bufSize,scrubDelta); //for (int i=len;i<bufSize;i++) buf[i] = 0;
//for (int i=0;i<len;i++) buf[i] = temp[i]; delete temp;
//for (int i=len;i<bufSize;i++) buf[i] = 0;
delete temp;
// Invert // Invert
if (invert) { if (invert) {
short aux; short aux;
for (int i=0;i<bufSize/2;i++) { for (int i=0;i<bufSize/2;i++) {
aux = buf[i]; aux = buf[i];
buf[i] = buf[bufSize-i-1]; buf[i] = buf[bufSize-i-1];
buf[bufSize-i-1] = aux; buf[bufSize-i-1] = aux;
}
} }
}
// Send data to provider // Send data to provider
scrubProvider->Append(buf,bufSize); scrubProvider->Append(buf,bufSize);
if (!player->IsPlaying()) player->Play(0,0xFFFFFFFFFFFF); if (!player->IsPlaying()) player->Play(0,0xFFFFFFFFFFFF);
delete buf; delete buf;
}
} }
// Update last pos and time // Update last pos and time

View file

@ -101,6 +101,7 @@ private:
int scrubTime; int scrubTime;
__int64 scrubLastPos; __int64 scrubLastPos;
bool scrubbing; bool scrubbing;
int scrubLastRate;
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
void OnMouseEvent(wxMouseEvent &event); void OnMouseEvent(wxMouseEvent &event);

View file

@ -238,6 +238,7 @@ void FrameMain::InitMenu() {
editMenu->AppendSeparator(); editMenu->AppendSeparator();
editMenu->Append(Menu_Edit_Select, _("&Select lines...\t") + Hotkeys.GetText(_T("Select lines")), _("Selects lines based on defined criterea")); editMenu->Append(Menu_Edit_Select, _("&Select lines...\t") + Hotkeys.GetText(_T("Select lines")), _("Selects lines based on defined criterea"));
editMenu->Append(Menu_Edit_Shift, _("S&hift times...\t") + Hotkeys.GetText(_T("Shift times")), _("Shift subtitles by time or frames")); editMenu->Append(Menu_Edit_Shift, _("S&hift times...\t") + Hotkeys.GetText(_T("Shift times")), _("Shift subtitles by time or frames"));
editMenu->Append(Menu_Edit_Sort, _("Sort by Time"), _("Sort all subtitles by their start times"));
editMenu->AppendSeparator(); editMenu->AppendSeparator();
AppendBitmapMenuItem (editMenu,Menu_Edit_Find, _("&Find...\t") + Hotkeys.GetText(_T("Find")), _("Find words in subtitles"),wxBITMAP(find_button)); AppendBitmapMenuItem (editMenu,Menu_Edit_Find, _("&Find...\t") + Hotkeys.GetText(_T("Find")), _("Find words in subtitles"),wxBITMAP(find_button));
editMenu->Append(Menu_Edit_Find_Next, _("Find next\t") + Hotkeys.GetText(_T("Find Next")), _("Find next match of last word")); editMenu->Append(Menu_Edit_Find_Next, _("Find next\t") + Hotkeys.GetText(_T("Find Next")), _("Find next match of last word"));

View file

@ -182,6 +182,7 @@ private:
void OnReplace (wxCommandEvent &event); void OnReplace (wxCommandEvent &event);
void OnJumpTo (wxCommandEvent &event); void OnJumpTo (wxCommandEvent &event);
void OnShift (wxCommandEvent &event); void OnShift (wxCommandEvent &event);
void OnSort (wxCommandEvent &event);
void OnOpenProperties (wxCommandEvent &event); void OnOpenProperties (wxCommandEvent &event);
void OnOpenStylesManager (wxCommandEvent &event); void OnOpenStylesManager (wxCommandEvent &event);
void OnOpenAttachments (wxCommandEvent &event); void OnOpenAttachments (wxCommandEvent &event);
@ -300,6 +301,7 @@ enum {
Menu_Edit_Select, Menu_Edit_Select,
Menu_Edit_Undo, Menu_Edit_Undo,
Menu_Edit_Redo, Menu_Edit_Redo,
Menu_Edit_Sort,
Menu_Edit_Find, Menu_Edit_Find,
Menu_Edit_Find_Next, Menu_Edit_Find_Next,
Menu_Edit_Replace, Menu_Edit_Replace,

View file

@ -165,6 +165,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Menu_Edit_Replace, FrameMain::OnReplace) EVT_MENU(Menu_Edit_Replace, FrameMain::OnReplace)
EVT_MENU(Menu_Edit_Shift, FrameMain::OnShift) EVT_MENU(Menu_Edit_Shift, FrameMain::OnShift)
EVT_MENU(Menu_Edit_Select, FrameMain::OnSelect) EVT_MENU(Menu_Edit_Select, FrameMain::OnSelect)
EVT_MENU(Menu_Edit_Sort, FrameMain::OnSort)
EVT_MENU(Menu_Tools_Properties, FrameMain::OnOpenProperties) EVT_MENU(Menu_Tools_Properties, FrameMain::OnOpenProperties)
EVT_MENU(Menu_Tools_Styles_Manager, FrameMain::OnOpenStylesManager) EVT_MENU(Menu_Tools_Styles_Manager, FrameMain::OnOpenStylesManager)
@ -1157,6 +1158,13 @@ void FrameMain::OnSelect (wxCommandEvent &event) {
} }
//////////////////
// Sort subtitles
void FrameMain::OnSort (wxCommandEvent &event) {
// TODO
}
////////////////////////// //////////////////////////
// Open styling assistant // Open styling assistant
void FrameMain::OnOpenStylingAssistant (wxCommandEvent &event) { void FrameMain::OnOpenStylingAssistant (wxCommandEvent &event) {