diff --git a/aegisub/src/ass_time.cpp b/aegisub/src/ass_time.cpp index b9ee97fbf..0798bdae3 100644 --- a/aegisub/src/ass_time.cpp +++ b/aegisub/src/ass_time.cpp @@ -162,7 +162,7 @@ int AssTime::GetMS () const { /// @param _ms /// void AssTime::SetMS (int ms) { - time = MID(0, ms, 10 * 60 * 60 * 1000 - 1); + time = mid(0, ms, 10 * 60 * 60 * 1000 - 1); } diff --git a/aegisub/src/audio_player_dsound.cpp b/aegisub/src/audio_player_dsound.cpp index 2fe021c1b..483150ce1 100644 --- a/aegisub/src/audio_player_dsound.cpp +++ b/aegisub/src/audio_player_dsound.cpp @@ -95,7 +95,7 @@ void DirectSoundPlayer::OpenStream() { int aim = waveFormat.nAvgBytesPerSec * 15/100; // 150 ms buffer int min = DSBSIZE_MIN; int max = DSBSIZE_MAX; - bufSize = MIN(MAX(min,aim),max); + bufSize = std::min(std::max(min,aim),max); DSBUFFERDESC desc; desc.dwSize = sizeof(DSBUFFERDESC); desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; diff --git a/aegisub/src/audio_player_dsound2.cpp b/aegisub/src/audio_player_dsound2.cpp index 5ed938d78..4fc27a9ce 100644 --- a/aegisub/src/audio_player_dsound2.cpp +++ b/aegisub/src/audio_player_dsound2.cpp @@ -292,7 +292,7 @@ void DirectSoundPlayer2Thread::Run() int aim = waveFormat.nAvgBytesPerSec * (wanted_latency*buffer_length)/1000; int min = DSBSIZE_MIN; 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; desc.dwSize = sizeof(DSBUFFERDESC); desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS; diff --git a/aegisub/src/audio_player_oss.cpp b/aegisub/src/audio_player_oss.cpp index c9cfec9cb..fb8d30364 100644 --- a/aegisub/src/audio_player_oss.cpp +++ b/aegisub/src/audio_player_oss.cpp @@ -295,11 +295,11 @@ OSSPlayerThread::OSSPlayerThread(OSSPlayer *par) : wxThread(wxTHREAD_JOINABLE) wxThread::ExitCode OSSPlayerThread::Entry() { // Use small enough writes for good timing accuracy with all // timing methods. - const int wsize = parent->rate / 25; + const unsigned long wsize = parent->rate / 25; void *buf = malloc(wsize * parent->bpf); 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, rsize, parent->volume); int written = ::write(parent->dspdev, buf, rsize * parent->bpf); diff --git a/aegisub/src/audio_provider_ram.cpp b/aegisub/src/audio_provider_ram.cpp index 36df8824e..dc2986850 100644 --- a/aegisub/src/audio_provider_ram.cpp +++ b/aegisub/src/audio_provider_ram.cpp @@ -70,7 +70,7 @@ RAMAudioProvider::RAMAudioProvider(AudioProvider *src) { // Allocate cache blocks try { for (int i = 0; i < blockcount; i++) { - blockcache[i] = new char[MIN(CacheBlockSize,ssize-i*CacheBlockSize)]; + blockcache[i] = new char[std::min(CacheBlockSize,ssize-i*CacheBlockSize)]; } } catch (...) { @@ -162,8 +162,7 @@ void RAMAudioProvider::GetAudio(void *buf, int64_t start, int64_t count) const { // Copy while (bytesremaining) { - int readsize=MIN(bytesremaining,CacheBlockSize); - readsize = MIN(readsize,CacheBlockSize - start_offset); + int readsize = std::min(bytesremaining, CacheBlockSize - start_offset); memcpy(charbuf,(char *)(blockcache[i++]+start_offset),readsize); diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 71d4218b5..f8551fcb1 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -585,7 +585,7 @@ void BaseGrid::DrawImage(wxDC &dc) { // Visible lines int drawPerScreen = h/lineHeight + 1; - int nDraw = MID(0,drawPerScreen,GetRows()-yPos); + int nDraw = mid(0,drawPerScreen,GetRows()-yPos); int maxH = (nDraw+1) * lineHeight; // Row colors @@ -819,7 +819,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { int row = event.GetY()/lineHeight + yPos - 1; bool headerClick = row < yPos; if (holding && !click) { - row = MID(0,row,GetRows()-1); + row = mid(0,row,GetRows()-1); } AssDialogue *dlg = GetDialogue(row); if (!dlg) row = 0; @@ -945,7 +945,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { void BaseGrid::ScrollTo(int y) { int 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) { yPos = nextY; if (scrollBar->IsEnabled()) scrollBar->SetThumbPosition(yPos); @@ -964,7 +964,7 @@ void BaseGrid::AdjustScrollbar() { int rows = GetRows(); bool barToEnable = drawPerScreen < rows+2; - yPos = MID(0,yPos,rows - drawPerScreen); + yPos = mid(0,yPos,rows - drawPerScreen); scrollBar->Freeze(); scrollBar->GetSize(&sw,&sh); @@ -1208,7 +1208,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) { extendRow = -1; } - int next = MID(0,curLine+dir*step,GetRows()-1); + int next = mid(0,curLine+dir*step,GetRows()-1); SetActiveLine(GetDialogue(next)); SelectRow(next); MakeCellVisible(next,0,false); @@ -1218,7 +1218,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) { // Move active only if (alt && !shift && !ctrl) { 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)); Refresh(false); MakeCellVisible(next,0,false); @@ -1229,7 +1229,7 @@ void BaseGrid::OnKeyPress(wxKeyEvent &event) { if (shift && !ctrl && !alt) { // Find end if (extendRow == -1) GetDialogueIndex(GetActiveLine()); - extendRow = MID(0,extendRow+dir*step,GetRows()-1); + extendRow = mid(0,extendRow+dir*step,GetRows()-1); // Set range int i1 = GetDialogueIndex(GetActiveLine()); diff --git a/aegisub/src/colorspace.cpp b/aegisub/src/colorspace.cpp index 894ef1125..9b142164d 100644 --- a/aegisub/src/colorspace.cpp +++ b/aegisub/src/colorspace.cpp @@ -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 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; @@ -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 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; diff --git a/aegisub/src/dialog_progress.cpp b/aegisub/src/dialog_progress.cpp index 21524dbdf..02ca179d9 100644 --- a/aegisub/src/dialog_progress.cpp +++ b/aegisub/src/dialog_progress.cpp @@ -99,7 +99,7 @@ void DialogProgress::SetProgress(int cur,int max) { // Check if it's the main thread, if so, just process it now if (wxIsMainThread()) { - gauge->SetValue(MID(0,value,100)); + gauge->SetValue(mid(0,value,100)); wxYield(); return; } @@ -124,7 +124,7 @@ void DialogProgress::SetProgress(int cur,int max) { void DialogProgress::OnUpdateProgress(wxCommandEvent &event) { 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); count--; } diff --git a/aegisub/src/dialog_timing_processor.cpp b/aegisub/src/dialog_timing_processor.cpp index 11f0ebb6c..ae5a1b9a3 100644 --- a/aegisub/src/dialog_timing_processor.cpp +++ b/aegisub/src/dialog_timing_processor.cpp @@ -123,7 +123,7 @@ DialogTimingProcessor::DialogTimingProcessor(wxWindow *parent,SubtitlesGrid *_gr 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->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.")); AdjacentSizer->Add(adjsEnable,0,wxRIGHT|wxEXPAND,10); AdjacentSizer->Add(adjsThresText,0,wxRIGHT|wxALIGN_CENTER,5); diff --git a/aegisub/src/dialog_video_details.cpp b/aegisub/src/dialog_video_details.cpp index 7edaafd33..e41a6ddd8 100644 --- a/aegisub/src/dialog_video_details.cpp +++ b/aegisub/src/dialog_video_details.cpp @@ -101,7 +101,7 @@ DialogVideoDetails::DialogVideoDetails(wxWindow *parent) /// 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++) { while (width % i == 0 && height % i == 0) { width /= i; diff --git a/aegisub/src/spline_curve.cpp b/aegisub/src/spline_curve.cpp index 9b67bb94d..839e35d31 100644 --- a/aegisub/src/spline_curve.cpp +++ b/aegisub/src/spline_curve.cpp @@ -99,7 +99,7 @@ void SplineCurve::Smooth(Vector2D const& P0,Vector2D const& P3,float smooth) { // Validate if (type != CURVE_LINE) return; if (p1 == p2) return; - smooth = MID(0.f,smooth,1.f); + smooth = mid(0.f,smooth,1.f); // Get points Vector2D P1 = p1; @@ -210,7 +210,7 @@ float SplineCurve::GetQuickDistance(Vector2D const& ref) const { /// @return /// 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 diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 86656b112..1b896563f 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -107,8 +107,8 @@ struct field_setter : public std::binary_function { void get_selection(SubsTextEditCtrl *TextEdit, int &start, int &end) { TextEdit->GetSelection(&start, &end); int len = TextEdit->GetText().size(); - start = MID(0,TextEdit->GetReverseUnicodePosition(start),len); - end = MID(0,TextEdit->GetReverseUnicodePosition(end),len); + start = mid(0,TextEdit->GetReverseUnicodePosition(start),len); + end = mid(0,TextEdit->GetReverseUnicodePosition(end),len); } /// @brief Get the value of a tag at a specified position in a line diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index 62f0efcd6..23da32acd 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -989,7 +989,7 @@ void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) { GetBoundsOfWordAtPosition(currentWordPos,start,end); 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 SetSelectionU(start,start+suggestion.Length()); diff --git a/aegisub/src/subtitles_provider_libass.cpp b/aegisub/src/subtitles_provider_libass.cpp index 5e32a0ced..a788bfe4d 100644 --- a/aegisub/src/subtitles_provider_libass.cpp +++ b/aegisub/src/subtitles_provider_libass.cpp @@ -210,7 +210,7 @@ void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) { int src_stride = img->stride; int dst_stride = frame.pitch[0]; 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; unsigned char *dst = frame.data[0] + (img->dst_y * dst_stride + img->dst_x * 4); unsigned int k,ck,t; diff --git a/aegisub/src/thesaurus_myspell.cpp b/aegisub/src/thesaurus_myspell.cpp index 176fd39c8..154071587 100644 --- a/aegisub/src/thesaurus_myspell.cpp +++ b/aegisub/src/thesaurus_myspell.cpp @@ -123,7 +123,7 @@ wxArrayString MySpellThesaurus::GetLanguageList() { // For each idxtionary match, see if it can find the corresponding .dat for (unsigned int i=0;i T tabs(T x) { return x < 0 ? -x : x; } -#ifndef MIN -#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 +template inline T mid(T a, T b, T c) { return std::max(a, std::min(b, c)); } #ifndef FORCEINLINE #ifdef __VISUALC__ diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 41b84d3b2..ee4a9536d 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -447,7 +447,7 @@ void VideoContext::SetAspectRatio(int type, double value) { if (type != 4) value = GetARFromType(type); arType = type; - arValue = MID(.5, value, 5.); + arValue = mid(.5, value, 5.); ARChange(arType, arValue); } diff --git a/aegisub/src/video_display.cpp b/aegisub/src/video_display.cpp index 3d070cfd8..aae95a357 100644 --- a/aegisub/src/video_display.cpp +++ b/aegisub/src/video_display.cpp @@ -487,12 +487,12 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) { } if (event.Leaving()) { - video.x = INT_MIN; - video.y = INT_MIN; + video.x = INT_MIN; + video.y = INT_MIN; } else { - video.x = event.GetX(); - video.y = event.GetY(); + video.x = event.GetX(); + video.y = event.GetY(); } tool->OnMouseEvent(event); diff --git a/aegisub/src/video_slider.cpp b/aegisub/src/video_slider.cpp index 6e25f88a9..7c473ec46 100644 --- a/aegisub/src/video_slider.cpp +++ b/aegisub/src/video_slider.cpp @@ -88,7 +88,7 @@ VideoSlider::~VideoSlider() { /// void VideoSlider::SetValue(int value) { if (val == value) return; - val = MID(0, value, max); + val = mid(0, value, max); Refresh(false); } @@ -284,7 +284,7 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) { // Fast move if (!ctrl && !shift && alt) { if (VideoContext::Get()->IsPlaying()) return; - int target = MID(0,val + direction * OPT_GET("Video/Slider/Fast Jump Step")->GetInt(),max); + int target = mid(0,val + direction * OPT_GET("Video/Slider/Fast Jump Step")->GetInt(),max); if (target != val) VideoContext::Get()->JumpToFrame(target); return; } diff --git a/aegisub/src/visual_tool_clip.cpp b/aegisub/src/visual_tool_clip.cpp index 256a798a3..784dbd662 100644 --- a/aegisub/src/visual_tool_clip.cpp +++ b/aegisub/src/visual_tool_clip.cpp @@ -142,10 +142,10 @@ void VisualToolClip::UpdateHold() { if (curY1 > curY2) std::swap(curY1,curY2); // Limit to video area - curX1 = MID(0,curX1,video.w); - curX2 = MID(0,curX2,video.w); - curY1 = MID(0,curY1,video.h); - curY2 = MID(0,curY2,video.h); + curX1 = mid(0,curX1,video.w); + curX2 = mid(0,curX2,video.w); + curY1 = mid(0,curY1,video.h); + curY2 = mid(0,curY2,video.h); SetFeaturePositions(); } diff --git a/aegisub/src/visual_tool_scale.cpp b/aegisub/src/visual_tool_scale.cpp index 94be5421f..e7ad56105 100644 --- a/aegisub/src/visual_tool_scale.cpp +++ b/aegisub/src/visual_tool_scale.cpp @@ -63,8 +63,8 @@ void VisualToolScale::Draw() { if (!curDiag) return; int len = 160; - 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 dx = mid(len/2+10,posx,video.w-len/2-30); + int dy = mid(len/2+10,posy,video.h-len/2-30); SetLineColour(colour[0]); SetFillColour(colour[1],0.3f);