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

View file

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

View file

@ -238,6 +238,7 @@ void FrameMain::InitMenu() {
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_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();
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"));

View file

@ -182,6 +182,7 @@ private:
void OnReplace (wxCommandEvent &event);
void OnJumpTo (wxCommandEvent &event);
void OnShift (wxCommandEvent &event);
void OnSort (wxCommandEvent &event);
void OnOpenProperties (wxCommandEvent &event);
void OnOpenStylesManager (wxCommandEvent &event);
void OnOpenAttachments (wxCommandEvent &event);
@ -300,6 +301,7 @@ enum {
Menu_Edit_Select,
Menu_Edit_Undo,
Menu_Edit_Redo,
Menu_Edit_Sort,
Menu_Edit_Find,
Menu_Edit_Find_Next,
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_Shift, FrameMain::OnShift)
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_Styles_Manager, FrameMain::OnOpenStylesManager)
@ -1157,6 +1158,13 @@ void FrameMain::OnSelect (wxCommandEvent &event) {
}
//////////////////
// Sort subtitles
void FrameMain::OnSort (wxCommandEvent &event) {
// TODO
}
//////////////////////////
// Open styling assistant
void FrameMain::OnOpenStylingAssistant (wxCommandEvent &event) {