Replace MIN/MAX/MID with std::min/std::max/mid

Originally committed to SVN as r5078.
This commit is contained in:
Thomas Goyne 2010-12-31 21:03:03 +00:00
parent c6a823c731
commit 833e69b09f
21 changed files with 41 additions and 52 deletions

View file

@ -162,7 +162,7 @@ int AssTime::GetMS () const {
/// @param _ms /// @param _ms
/// ///
void AssTime::SetMS (int ms) { void AssTime::SetMS (int ms) {
time = MID(0, ms, 10 * 60 * 60 * 1000 - 1); time = mid(0, ms, 10 * 60 * 60 * 1000 - 1);
} }

View file

@ -95,7 +95,7 @@ void DirectSoundPlayer::OpenStream() {
int aim = waveFormat.nAvgBytesPerSec * 15/100; // 150 ms buffer int aim = waveFormat.nAvgBytesPerSec * 15/100; // 150 ms buffer
int min = DSBSIZE_MIN; int min = DSBSIZE_MIN;
int max = DSBSIZE_MAX; int max = DSBSIZE_MAX;
bufSize = MIN(MAX(min,aim),max); bufSize = std::min(std::max(min,aim),max);
DSBUFFERDESC desc; DSBUFFERDESC desc;
desc.dwSize = sizeof(DSBUFFERDESC); desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;

View file

@ -292,7 +292,7 @@ void DirectSoundPlayer2Thread::Run()
int aim = waveFormat.nAvgBytesPerSec * (wanted_latency*buffer_length)/1000; int aim = waveFormat.nAvgBytesPerSec * (wanted_latency*buffer_length)/1000;
int min = DSBSIZE_MIN; int min = DSBSIZE_MIN;
int max = DSBSIZE_MAX; int max = DSBSIZE_MAX;
DWORD bufSize = MIN(MAX(min,aim),max); // size of entier playback buffer DWORD bufSize = mid(min,aim,max); // size of entier playback buffer
DSBUFFERDESC desc; DSBUFFERDESC desc;
desc.dwSize = sizeof(DSBUFFERDESC); desc.dwSize = sizeof(DSBUFFERDESC);
desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;

View file

@ -295,11 +295,11 @@ OSSPlayerThread::OSSPlayerThread(OSSPlayer *par) : wxThread(wxTHREAD_JOINABLE)
wxThread::ExitCode OSSPlayerThread::Entry() { wxThread::ExitCode OSSPlayerThread::Entry() {
// Use small enough writes for good timing accuracy with all // Use small enough writes for good timing accuracy with all
// timing methods. // timing methods.
const int wsize = parent->rate / 25; const unsigned long wsize = parent->rate / 25;
void *buf = malloc(wsize * parent->bpf); void *buf = malloc(wsize * parent->bpf);
while (!TestDestroy() && parent->cur_frame < parent->end_frame) { while (!TestDestroy() && parent->cur_frame < parent->end_frame) {
int rsize = MIN(wsize, parent->end_frame - parent->cur_frame); int rsize = std::min(wsize, parent->end_frame - parent->cur_frame);
parent->provider->GetAudioWithVolume(buf, parent->cur_frame, parent->provider->GetAudioWithVolume(buf, parent->cur_frame,
rsize, parent->volume); rsize, parent->volume);
int written = ::write(parent->dspdev, buf, rsize * parent->bpf); int written = ::write(parent->dspdev, buf, rsize * parent->bpf);

View file

@ -70,7 +70,7 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *src) {
// Allocate cache blocks // Allocate cache blocks
try { try {
for (int i = 0; i < blockcount; i++) { for (int i = 0; i < blockcount; i++) {
blockcache[i] = new char[MIN(CacheBlockSize,ssize-i*CacheBlockSize)]; blockcache[i] = new char[std::min<size_t>(CacheBlockSize,ssize-i*CacheBlockSize)];
} }
} }
catch (...) { catch (...) {
@ -162,8 +162,7 @@ void RAMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) const {
// Copy // Copy
while (bytesremaining) { while (bytesremaining) {
int readsize=MIN(bytesremaining,CacheBlockSize); int readsize = std::min<int>(bytesremaining, CacheBlockSize - start_offset);
readsize = MIN(readsize,CacheBlockSize - start_offset);
memcpy(charbuf,(char *)(blockcache[i++]+start_offset),readsize); memcpy(charbuf,(char *)(blockcache[i++]+start_offset),readsize);

View file

@ -585,7 +585,7 @@ void BaseGrid::DrawImage(wxDC &dc) {
// Visible lines // Visible lines
int drawPerScreen = h/lineHeight + 1; int drawPerScreen = h/lineHeight + 1;
int nDraw = MID(0,drawPerScreen,GetRows()-yPos); int nDraw = mid(0,drawPerScreen,GetRows()-yPos);
int maxH = (nDraw+1) * lineHeight; int maxH = (nDraw+1) * lineHeight;
// Row colors // Row colors
@ -819,7 +819,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
int row = event.GetY()/lineHeight + yPos - 1; int row = event.GetY()/lineHeight + yPos - 1;
bool headerClick = row < yPos; bool headerClick = row < yPos;
if (holding && !click) { if (holding && !click) {
row = MID(0,row,GetRows()-1); row = mid(0,row,GetRows()-1);
} }
AssDialogue *dlg = GetDialogue(row); AssDialogue *dlg = GetDialogue(row);
if (!dlg) row = 0; if (!dlg) row = 0;
@ -945,7 +945,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
void BaseGrid::ScrollTo(int y) { void BaseGrid::ScrollTo(int y) {
int w,h; int w,h;
GetClientSize(&w,&h); GetClientSize(&w,&h);
int nextY = MID(0,y,GetRows()+2 - h/lineHeight); int nextY = mid(0,y,GetRows()+2 - h/lineHeight);
if (yPos != nextY) { if (yPos != nextY) {
yPos = nextY; yPos = nextY;
if (scrollBar->IsEnabled()) scrollBar->SetThumbPosition(yPos); if (scrollBar->IsEnabled()) scrollBar->SetThumbPosition(yPos);
@ -964,7 +964,7 @@ void BaseGrid::AdjustScrollbar() {
int rows = GetRows(); int rows = GetRows();
bool barToEnable = drawPerScreen < rows+2; bool barToEnable = drawPerScreen < rows+2;
yPos = MID(0,yPos,rows - drawPerScreen); yPos = mid(0,yPos,rows - drawPerScreen);
scrollBar->Freeze(); scrollBar->Freeze();
scrollBar->GetSize(&sw,&sh); scrollBar->GetSize(&sw,&sh);
@ -1208,7 +1208,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
extendRow = -1; extendRow = -1;
} }
int next = MID(0,curLine+dir*step,GetRows()-1); int next = mid(0,curLine+dir*step,GetRows()-1);
SetActiveLine(GetDialogue(next)); SetActiveLine(GetDialogue(next));
SelectRow(next); SelectRow(next);
MakeCellVisible(next,0,false); MakeCellVisible(next,0,false);
@ -1218,7 +1218,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
// Move active only // Move active only
if (alt && !shift && !ctrl) { if (alt && !shift && !ctrl) {
extendRow = -1; extendRow = -1;
int next = MID(0,GetDialogueIndex(GetActiveLine())+dir*step,GetRows()-1); int next = mid(0,GetDialogueIndex(GetActiveLine())+dir*step,GetRows()-1);
SetActiveLine(GetDialogue(next)); SetActiveLine(GetDialogue(next));
Refresh(false); Refresh(false);
MakeCellVisible(next,0,false); MakeCellVisible(next,0,false);
@ -1229,7 +1229,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) {
if (shift && !ctrl && !alt) { if (shift && !ctrl && !alt) {
// Find end // Find end
if (extendRow == -1) GetDialogueIndex(GetActiveLine()); if (extendRow == -1) GetDialogueIndex(GetActiveLine());
extendRow = MID(0,extendRow+dir*step,GetRows()-1); extendRow = mid(0,extendRow+dir*step,GetRows()-1);
// Set range // Set range
int i1 = GetDialogueIndex(GetActiveLine()); int i1 = GetDialogueIndex(GetActiveLine());

View file

@ -311,7 +311,7 @@ void rgb_to_hsl(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
float r = R/255.f, g = G/255.f, b = B/255.f; float r = R/255.f, g = G/255.f, b = B/255.f;
float h, s, l; float h, s, l;
float maxrgb = MAX(r, MAX(g, b)), minrgb = MIN(r, MIN(g, b)); float maxrgb = std::max(r, std::max(g, b)), minrgb = std::min(r, std::min(g, b));
l = (minrgb + maxrgb) / 2; l = (minrgb + maxrgb) / 2;
@ -356,7 +356,7 @@ void rgb_to_hsv(int R, int G, int B, unsigned char *H, unsigned char *S, unsigne
float r = R/255.f, g = G/255.f, b = B/255.f; float r = R/255.f, g = G/255.f, b = B/255.f;
float h, s, v; float h, s, v;
float maxrgb = MAX(r, MAX(g, b)), minrgb = MIN(r, MIN(g, b)); float maxrgb = std::max(r, std::max(g, b)), minrgb = std::min(r, std::min(g, b));
v = maxrgb; v = maxrgb;

View file

@ -99,7 +99,7 @@ void DialogProgress::SetProgress(int cur,int max) {
// Check if it's the main thread, if so, just process it now // Check if it's the main thread, if so, just process it now
if (wxIsMainThread()) { if (wxIsMainThread()) {
gauge->SetValue(MID(0,value,100)); gauge->SetValue(mid(0,value,100));
wxYield(); wxYield();
return; return;
} }
@ -124,7 +124,7 @@ void DialogProgress::SetProgress(int cur,int max) {
void DialogProgress::OnUpdateProgress(wxCommandEvent &event) void DialogProgress::OnUpdateProgress(wxCommandEvent &event)
{ {
int value = event.GetInt(); int value = event.GetInt();
if (gauge->GetValue() != value) gauge->SetValue(MID(0,value,100)); if (gauge->GetValue() != value) gauge->SetValue(mid(0,value,100));
wxMutexLocker locker(mutex); wxMutexLocker locker(mutex);
count--; count--;
} }

View file

@ -123,7 +123,7 @@ DialogTimingProcessor::DialogTimingProcessor(wxWindow *parent,SubtitlesGrid *_gr
wxStaticText *adjsThresText = new wxStaticText(this,-1,_("Threshold:"),wxDefaultPosition,wxDefaultSize,wxALIGN_CENTRE); wxStaticText *adjsThresText = new wxStaticText(this,-1,_("Threshold:"),wxDefaultPosition,wxDefaultSize,wxALIGN_CENTRE);
adjacentThres = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(60,-1),0,NumValidator(&adjsThresTime)); adjacentThres = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(60,-1),0,NumValidator(&adjsThresTime));
adjacentThres->SetToolTip(_("Maximum difference between start and end time for two subtitles to be made continuous, in milliseconds.")); adjacentThres->SetToolTip(_("Maximum difference between start and end time for two subtitles to be made continuous, in milliseconds."));
adjacentBias = new wxSlider(this,-1,MID(0,int(OPT_GET("Tool/Timing Post Processor/Adjacent Bias")->GetDouble()*100),100),0,100,wxDefaultPosition,wxSize(-1,20)); adjacentBias = new wxSlider(this,-1,mid(0,int(OPT_GET("Tool/Timing Post Processor/Adjacent Bias")->GetDouble()*100),100),0,100,wxDefaultPosition,wxSize(-1,20));
adjacentBias->SetToolTip(_("Sets how to set the adjoining of lines. If set totally to left, it will extend start time of the second line; if totally to right, it will extend the end time of the first line.")); adjacentBias->SetToolTip(_("Sets how to set the adjoining of lines. If set totally to left, it will extend start time of the second line; if totally to right, it will extend the end time of the first line."));
AdjacentSizer->Add(adjsEnable,0,wxRIGHT|wxEXPAND,10); AdjacentSizer->Add(adjsEnable,0,wxRIGHT|wxEXPAND,10);
AdjacentSizer->Add(adjsThresText,0,wxRIGHT|wxALIGN_CENTER,5); AdjacentSizer->Add(adjsThresText,0,wxRIGHT|wxALIGN_CENTER,5);

View file

@ -101,7 +101,7 @@ DialogVideoDetails::DialogVideoDetails(wxWindow *parent)
/// ///
wxString DialogVideoDetails::PrettyAR(int width, int height) wxString DialogVideoDetails::PrettyAR(int width, int height)
{ {
int limit = (int)ceil(sqrt(double(MIN(width, height)))); int limit = (int)ceil(sqrt(double(std::min(width, height))));
for (int i=2;i<=limit;i++) { for (int i=2;i<=limit;i++) {
while (width % i == 0 && height % i == 0) { while (width % i == 0 && height % i == 0) {
width /= i; width /= i;

View file

@ -99,7 +99,7 @@ void SplineCurve::Smooth(Vector2D const& P0,Vector2D const& P3,float smooth) {
// Validate // Validate
if (type != CURVE_LINE) return; if (type != CURVE_LINE) return;
if (p1 == p2) return; if (p1 == p2) return;
smooth = MID(0.f,smooth,1.f); smooth = mid(0.f,smooth,1.f);
// Get points // Get points
Vector2D P1 = p1; Vector2D P1 = p1;
@ -210,7 +210,7 @@ float SplineCurve::GetQuickDistance(Vector2D const& ref) const {
/// @return /// @return
/// ///
float SplineCurve::GetClosestSegmentPart(Vector2D const& pt1,Vector2D const& pt2,Vector2D const& pt3) const { float SplineCurve::GetClosestSegmentPart(Vector2D const& pt1,Vector2D const& pt2,Vector2D const& pt3) const {
return MID(0.f,(pt3-pt1).Dot(pt2-pt1)/(pt2-pt1).SquareLen(),1.f); return mid(0.f,(pt3-pt1).Dot(pt2-pt1)/(pt2-pt1).SquareLen(),1.f);
} }
/// @brief Closest distance between p3 and segment p1-p2 /// @brief Closest distance between p3 and segment p1-p2

View file

@ -107,8 +107,8 @@ struct field_setter : public std::binary_function<AssDialogue*, T, void> {
void get_selection(SubsTextEditCtrl *TextEdit, int &start, int &end) { void get_selection(SubsTextEditCtrl *TextEdit, int &start, int &end) {
TextEdit->GetSelection(&start, &end); TextEdit->GetSelection(&start, &end);
int len = TextEdit->GetText().size(); int len = TextEdit->GetText().size();
start = MID(0,TextEdit->GetReverseUnicodePosition(start),len); start = mid(0,TextEdit->GetReverseUnicodePosition(start),len);
end = MID(0,TextEdit->GetReverseUnicodePosition(end),len); end = mid(0,TextEdit->GetReverseUnicodePosition(end),len);
} }
/// @brief Get the value of a tag at a specified position in a line /// @brief Get the value of a tag at a specified position in a line

View file

@ -989,7 +989,7 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
GetBoundsOfWordAtPosition(currentWordPos,start,end); GetBoundsOfWordAtPosition(currentWordPos,start,end);
wxString text = GetText(); wxString text = GetText();
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1)); SetText(text.Left(std::max(0,start)) + suggestion + text.Mid(end+1));
// Set selection // Set selection
SetSelectionU(start,start+suggestion.Length()); SetSelectionU(start,start+suggestion.Length());

View file

@ -210,7 +210,7 @@ void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) {
int src_stride = img->stride; int src_stride = img->stride;
int dst_stride = frame.pitch[0]; int dst_stride = frame.pitch[0];
int dst_delta = dst_stride - img->w*4; int dst_delta = dst_stride - img->w*4;
//int stride = MIN(src_stride,dst_stride); //int stride = std::min(src_stride,dst_stride);
const unsigned char *src = img->bitmap; const unsigned char *src = img->bitmap;
unsigned char *dst = frame.data[0] + (img->dst_y * dst_stride + img->dst_x * 4); unsigned char *dst = frame.data[0] + (img->dst_y * dst_stride + img->dst_x * 4);
unsigned int k,ck,t; unsigned int k,ck,t;

View file

@ -123,7 +123,7 @@ wxArrayString MySpellThesaurus::GetLanguageList() {
// For each idxtionary match, see if it can find the corresponding .dat // For each idxtionary match, see if it can find the corresponding .dat
for (unsigned int i=0;i<idx.Count();i++) { for (unsigned int i=0;i<idx.Count();i++) {
wxString curdat = idx[i].Left(MAX(0,signed(idx[i].Length())-4)) + _T(".dat"); wxString curdat = idx[i].Left(std::max(0,signed(idx[i].Length())-4)) + _T(".dat");
for (unsigned int j=0;j<dat.Count();j++) { for (unsigned int j=0;j<dat.Count();j++) {
// Found match // Found match
if (curdat == dat[j]) { if (curdat == dat[j]) {

View file

@ -74,17 +74,7 @@ void RestartAegisub();
/// @brief Templated abs() function /// @brief Templated abs() function
template <typename T> T tabs(T x) { return x < 0 ? -x : x; } template <typename T> T tabs(T x) { return x < 0 ? -x : x; }
#ifndef MIN template<typename T> inline T mid(T a, T b, T c) { return std::max(a, std::min(b, c)); }
#define MIN(a,b) ((a)<(b))?(a):(b)
#endif
#ifndef MAX
#define MAX(a,b) ((a)>(b))?(a):(b)
#endif
#ifndef MID
#define MID(a,b,c) MAX((a),MIN((b),(c)))
#endif
#ifndef FORCEINLINE #ifndef FORCEINLINE
#ifdef __VISUALC__ #ifdef __VISUALC__

View file

@ -447,7 +447,7 @@ void VideoContext::SetAspectRatio(int type, double value) {
if (type != 4) value = GetARFromType(type); if (type != 4) value = GetARFromType(type);
arType = type; arType = type;
arValue = MID(.5, value, 5.); arValue = mid(.5, value, 5.);
ARChange(arType, arValue); ARChange(arType, arValue);
} }

View file

@ -88,7 +88,7 @@ VideoSlider::~VideoSlider() {
/// ///
void VideoSlider::SetValue(int value) { void VideoSlider::SetValue(int value) {
if (val == value) return; if (val == value) return;
val = MID(0, value, max); val = mid(0, value, max);
Refresh(false); Refresh(false);
} }
@ -284,7 +284,7 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) {
// Fast move // Fast move
if (!ctrl && !shift && alt) { if (!ctrl && !shift && alt) {
if (VideoContext::Get()->IsPlaying()) return; if (VideoContext::Get()->IsPlaying()) return;
int target = MID(0,val + direction * OPT_GET("Video/Slider/Fast Jump Step")->GetInt(),max); int target = mid<int>(0,val + direction * OPT_GET("Video/Slider/Fast Jump Step")->GetInt(),max);
if (target != val) VideoContext::Get()->JumpToFrame(target); if (target != val) VideoContext::Get()->JumpToFrame(target);
return; return;
} }

View file

@ -142,10 +142,10 @@ void VisualToolClip::UpdateHold() {
if (curY1 > curY2) std::swap(curY1,curY2); if (curY1 > curY2) std::swap(curY1,curY2);
// Limit to video area // Limit to video area
curX1 = MID(0,curX1,video.w); curX1 = mid(0,curX1,video.w);
curX2 = MID(0,curX2,video.w); curX2 = mid(0,curX2,video.w);
curY1 = MID(0,curY1,video.h); curY1 = mid(0,curY1,video.h);
curY2 = MID(0,curY2,video.h); curY2 = mid(0,curY2,video.h);
SetFeaturePositions(); SetFeaturePositions();
} }

View file

@ -63,8 +63,8 @@ void VisualToolScale::Draw() {
if (!curDiag) return; if (!curDiag) return;
int len = 160; int len = 160;
int dx = MID(len/2+10,posx,video.w-len/2-30); int dx = mid(len/2+10,posx,video.w-len/2-30);
int dy = MID(len/2+10,posy,video.h-len/2-30); int dy = mid(len/2+10,posy,video.h-len/2-30);
SetLineColour(colour[0]); SetLineColour(colour[0]);
SetFillColour(colour[1],0.3f); SetFillColour(colour[1],0.3f);