Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | List of all members
NumericConverter Class Reference

NumericConverter provides the advanced formatting control used in the selection bar of Audacity. More...

#include <NumericTextCtrl.h>

Inheritance diagram for NumericConverter:
[legend]
Collaboration diagram for NumericConverter:
[legend]

Classes

struct  FormatStrings
 

Public Types

enum  Type { TIME , ATIME , FREQUENCY , BANDWIDTH }
 

Public Member Functions

 NumericConverter (Type type, const NumericFormatSymbol &formatName={}, double value=0.0f, double sampleRate=1.0f)
 
 NumericConverter (const NumericConverter &)
 
virtual ~NumericConverter ()
 
virtual void ValueToControls ()
 
virtual void ValueToControls (double rawValue, bool nearest=true)
 
virtual void ControlsToValue ()
 
void PrintDebugInfo ()
 
bool SetFormatName (const NumericFormatSymbol &formatName)
 
bool SetFormatString (const FormatStrings &formatString)
 
void SetSampleRate (double sampleRate)
 
void SetValue (double newValue)
 
void SetMinValue (double minValue)
 
void ResetMinValue ()
 
void SetMaxValue (double maxValue)
 
void ResetMaxValue ()
 
double GetValue ()
 
wxString GetString ()
 
int GetFormatIndex ()
 
int GetNumBuiltins ()
 
NumericFormatSymbol GetBuiltinName (const int index)
 
FormatStrings GetBuiltinFormat (const int index)
 
FormatStrings GetBuiltinFormat (const NumericFormatSymbol &name)
 
void Adjust (int steps, int dir)
 
void Increment ()
 
void Decrement ()
 

Static Public Member Functions

static NumericFormatSymbol DefaultSelectionFormat ()
 
static NumericFormatSymbol TimeAndSampleFormat ()
 
static NumericFormatSymbol SecondsFormat ()
 
static NumericFormatSymbol HoursMinsSecondsFormat ()
 
static NumericFormatSymbol HundredthsFormat ()
 
static NumericFormatSymbol HertzFormat ()
 
static NumericFormatSymbol LookupFormat (Type type, const wxString &id)
 

Protected Attributes

Type mType
 
double mValue
 
double mMinValue
 
double mMaxValue
 
double mInvalidValue
 
FormatStrings mFormatString
 
std::vector< NumericFieldmFields
 
wxString mPrefix
 
wxString mValueTemplate
 
wxString mValueMask
 
wxString mValueString
 
double mScalingFactor
 
double mSampleRate
 
bool mNtscDrop
 
int mFocusedDigit
 
std::vector< DigitInfomDigits
 
const BuiltinFormatStringmBuiltinFormatStrings
 
const size_t mNBuiltins
 
int mDefaultNdx
 

Private Member Functions

void ParseFormatString (const TranslatableString &untranslatedFormat)
 

Detailed Description

NumericConverter provides the advanced formatting control used in the selection bar of Audacity.

NumericConverter has all the time conversion and snapping functionality that used to live in NumericTextCtrl. The idea is to have a GUI-less class which can do the conversions, so that we can use it in sanpping without having a window created each time.

NumericConverter

Any negative value given to the converter is considered invalid and all digit positions of the resulting string will be filled with hyphens. Otherwise:

The NumericConverter makes use of a format string to specify the exact way that a single value is split into several fields, such as the hh:mm:ss format. The advantage of this format string is that it is very small and compact, but human-readable and somewhat intuitive, so that it's easy to add NEW layouts in the future. It's also designed to make it easier to add i18n support, since the way that numbers are displayed in different languages could conceivably vary a lot.

The number to be formatted may be expressed in seconds, so the format string can specify the relationship of each field to the number of seconds.

The class is also reused to format some non-time values such as frequency and log of frequency.

Let's start by considering an example: here's the format string that prints an integer number of seconds in the hour minute second h:m:s format:

:60:60

The "*" is a wildcard, saying that the leftmost field can contain numbers of arbitrary magnitude. The next character, ':', since it is not a digit or a wildcard, is interpreted as a delimiter, and will be displayed between those fields. The next number, 60, indicates that the range of the next field (minutes) is 60. Then there's another ':' delimiter, and finally the last field (seconds) is 60. So, if you give it a number like 3758 it is formatted as:

3758 seconds, "*:60:60" -> "1:2:38"

Note that 3758 = 1*60*60 + 2*60 + 38.

When NumericConverter formats an integer, you can think of its process as working from right to left. Given the value "3758", it fills in the seconds by dividing by 60, sticking the remainder in the seconds field and then passing the quotient to the next field to the left.

In order to format a field with leading zeros, simply add a leading zero to that field, like this:

3758 seconds, "*:060:060" -> "1:02:38"

In order to format fractions, simply include a field delimiter ending with a decimal point. If the delimiter is simply '.' with nothing else, then the '.' is actually displayed. Otherwise the '.' is dropped, and the other characters in the delimiter are displayed instead.

Here's how we'd display hours, minutes, and seconds with three decimal places after the seconds:

3758.5 seconds, "*:060:060.01000" -> "1:02:38.500"

Similarly, here's how we'd display the fractional part of seconds as film frames (24 per second) instead of milliseconds:

3758.5 seconds, "*:060:060 and .24 frames" -> "1:02:38 and 12 frames"

Note that the decimal '.' is associated with the delimiter, not with the 24.

Additionally, the special character '#' can be used in place of a number to represent the current sample rate. Use '0#' to add leading zeros to that field. For example:

3758.5 seconds, "*:060:060+.#samples" -> "1:02:38+22050samples"

(Almost) Finally, there is a rule that allows you to change the units into something other than seconds. To do this, put a "|" character on the far right, followed by a number specifying the scaling factor. As an exception to previous rules, decimal points are allowed in the final scaling factor - the period is not interpreted as it would be before the "|" character. (This is fine, because all previous fields must be integers to make sense.) Anyway, if you include a scaling factor after a "|", the number will be multiplied by this factor before it is formatted. For example, to express the current time in NTSC frames (~29.97 fps), you could use the following formatting:

3758.5 seconds, "*.01000 frames|29.97002997" -> "112642.358 frames"

Finally there is a further special character that can be used after a "|" and that is "N". This applies special rule for NTSC drop-frame timecode.

Summary of format string rules:

Definition at line 47 of file NumericTextCtrl.h.

Member Enumeration Documentation

◆ Type

Enumerator
TIME 
ATIME 
FREQUENCY 
BANDWIDTH 

Definition at line 51 of file NumericTextCtrl.h.

51 {
52 TIME,
53 ATIME, // for Audio time control.
56 };

Constructor & Destructor Documentation

◆ NumericConverter() [1/2]

NumericConverter::NumericConverter ( Type  type,
const NumericFormatSymbol formatName = {},
double  value = 0.0f,
double  sampleRate = 1.0f 
)

Definition at line 722 of file NumericTextCtrl.cpp.

728{
731 mInvalidValue = -1.0;
732
733 mDefaultNdx = 0;
734
735 mType = type;
736
737 if (type == NumericConverter::TIME )
738 mDefaultNdx = 4; // Default to "hh:mm:ss + milliseconds".
739
740 mScalingFactor = 1.0f;
741 mSampleRate = 1.0f;
742 mNtscDrop = false;
743
744 mFocusedDigit = 0;
745
746 mValue = value; // used in SetSampleRate, reassigned later
747
748 SetSampleRate(sampleRate);
749 SetFormatName(formatName);
750 SetValue(value); // mValue got overridden to -1 in ControlsToValue(), reassign
751}
const BuiltinFormatString * mBuiltinFormatStrings
const size_t mNBuiltins
void SetSampleRate(double sampleRate)
void SetValue(double newValue)
bool SetFormatName(const NumericFormatSymbol &formatName)
const BuiltinFormatString * ChooseBuiltinFormatStrings(NumericConverter::Type type)
size_t ChooseNBuiltinFormatStrings(NumericConverter::Type type)

References mDefaultNdx, mFocusedDigit, mInvalidValue, mNtscDrop, mSampleRate, mScalingFactor, mType, mValue, ResetMaxValue(), ResetMinValue(), SetFormatName(), SetSampleRate(), SetValue(), and TIME.

Here is the call graph for this function:

◆ NumericConverter() [2/2]

NumericConverter::NumericConverter ( const NumericConverter )
default

◆ ~NumericConverter()

NumericConverter::~NumericConverter ( )
virtual

Definition at line 945 of file NumericTextCtrl.cpp.

946{
947}

Member Function Documentation

◆ Adjust()

void NumericConverter::Adjust ( int  steps,
int  dir 
)

Definition at line 1249 of file NumericTextCtrl.cpp.

1250{
1251 // It is possible and "valid" for steps to be zero if a
1252 // high precision device is being used and wxWidgets supports
1253 // reporting a higher precision...Mac wx3 does.
1254 if (steps == 0)
1255 return;
1256
1257 wxASSERT(dir == -1 || dir == 1);
1258 wxASSERT(steps > 0);
1259 if (steps < 0)
1260 steps = -steps;
1261
1262 while (steps != 0)
1263 {
1264 for (size_t i = 0; i < mFields.size(); i++)
1265 {
1266 if ((mDigits[mFocusedDigit].pos >= mFields[i].pos) &&
1267 (mDigits[mFocusedDigit].pos < mFields[i].pos + mFields[i].digits))
1268 { //it's this field
1269 if (!mNtscDrop)
1270 {
1272 }
1273 else
1274 {
1275 mNtscDrop = false;
1277 mNtscDrop = true;
1278 }
1279
1280 if (mValue < 0)
1281 mValue = 0;
1282
1284
1285 double mult = pow(10., mFields[i].digits - (mDigits[mFocusedDigit].pos - mFields[i].pos) - 1);
1286 if (mFields[i].frac)
1287 {
1288 mValue += ((mult / (double)mFields[i].base) * dir);
1289 }
1290 else
1291 {
1292 mValue += ((mult * (double)mFields[i].base) * dir);
1293 }
1294
1295 if (mNtscDrop)
1296 {
1297 if ((mValue - (int)mValue) * 30 < 2)
1298 {
1299 if ((((int)mValue) % 60 == 0) && (((int)mValue) % 600 != 0))
1300 {
1301 mValue = (int)mValue + (dir > 0 ? 2. : -1.) / 30.;
1302 }
1303 }
1304 }
1305
1306 if (mValue < 0.)
1307 {
1308 mValue = 0.;
1309 }
1310
1311 mValue = std::max(mMinValue, std::min(mMaxValue, mValue));
1312
1314
1315 if (!mNtscDrop)
1316 {
1318 }
1319 else
1320 {
1321 mNtscDrop = false;
1323 mNtscDrop = true;
1325 }
1326 break;
1327 }
1328 }
1329 steps--;
1330 }
1331
1333}
int min(int a, int b)
virtual void ControlsToValue()
virtual void ValueToControls()
std::vector< DigitInfo > mDigits
std::vector< NumericField > mFields

References ControlsToValue(), mDigits, mFields, mFocusedDigit, min(), mMaxValue, mMinValue, mNtscDrop, mScalingFactor, mValue, and ValueToControls().

Referenced by Decrement(), Increment(), NumericTextCtrl::OnKeyDown(), and NumericTextCtrl::OnMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ControlsToValue()

void NumericConverter::ControlsToValue ( )
virtual

Reimplemented in NumericTextCtrl.

Definition at line 1060 of file NumericTextCtrl.cpp.

1061{
1062 unsigned int i;
1063 double t = 0.0;
1064
1065 if (mFields.size() > 0 &&
1066 mValueString.Mid(mFields[0].pos, 1) == wxChar('-')) {
1068 return;
1069 }
1070
1071 for(i = 0; i < mFields.size(); i++) {
1072 long val;
1073 mFields[i].str = mValueString.Mid(mFields[i].pos,
1074 mFields[i].digits);
1075 mFields[i].str.ToLong(&val);
1076 if (mFields[i].frac)
1077 t += (val / (double)mFields[i].base);
1078 else
1079 t += (val * (double)mFields[i].base);
1080 }
1081
1082 t /= mScalingFactor;
1083 if(mNtscDrop) {
1084 int t_int = (int)(t + .000000001);
1085 double t_frac = (t - t_int);
1086 int tenMins = t_int/600;
1087 double frames = tenMins*17982;
1088 t_int -= tenMins*600;
1089 int mins = t_int/60;
1090 int addMins = 0;
1091 if( mins > 0 ) {
1092 frames += 1800;
1093 addMins = mins - 1;
1094 }
1095 frames += addMins * 1798;
1096 t_int -= mins*60;
1097 if( mins == 0 ) //first min of a block of 10, don't drop frames 0 and 1
1098 frames += t_int * 30 + t_frac*30.;
1099 else { //drop frames 0 and 1 of first seconds of these minutes
1100 if( t_int > 0 )
1101 frames += 28 + (t_int-1)*30 + t_frac*30.;
1102 else
1103 frames += t_frac*30. -2.;
1104 }
1105 t = frames * 1.001 / 30.;
1106 }
1107
1108 mValue = std::max(mMinValue, std::min(mMaxValue, t));
1109}

References mFields, min(), mInvalidValue, mMaxValue, mMinValue, mNtscDrop, mScalingFactor, mValue, and mValueString.

Referenced by Adjust(), NumericTextCtrl::ControlsToValue(), GetValue(), SetFormatString(), SetSampleRate(), SetValue(), SnapManager::Snap(), and ProjectSelectionManager::SnapSelection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Decrement()

void NumericConverter::Decrement ( )

Definition at line 1243 of file NumericTextCtrl.cpp.

1244{
1245 mFocusedDigit = mDigits.size() - 1;
1246 Adjust(1, -1);
1247}
void Adjust(int steps, int dir)

References Adjust(), mDigits, and mFocusedDigit.

Referenced by anonymous_namespace{SelectMenus.cpp}::GridMove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultSelectionFormat()

NumericFormatSymbol NumericConverter::DefaultSelectionFormat ( )
static

Definition at line 690 of file NumericTextCtrl.cpp.

691{ return TimeConverterFormats_[4].name; }
static const BuiltinFormatString TimeConverterFormats_[]
array of formats the control knows about internally array of string pairs for name of the format and ...
NumericFormatSymbol name

References BuiltinFormatString::name, and anonymous_namespace{NumericTextCtrl.cpp}::TimeConverterFormats_.

Referenced by EffectBase::DoEffect(), EffectChangeSpeed::DoLoadFactoryDefaults(), EffectChangeSpeed::EffectChangeSpeed(), and LookupFormat().

Here is the caller graph for this function:

◆ GetBuiltinFormat() [1/2]

auto NumericConverter::GetBuiltinFormat ( const int  index)

Definition at line 1209 of file NumericTextCtrl.cpp.

1210{
1211 if (index >= 0 && index < GetNumBuiltins())
1213
1214 return {};
1215}
NumericConverter::FormatStrings formatStrings

Referenced by GetFormatIndex(), NumericTextCtrl::OnContext(), TimeToolBar::SetAudioTimeFormat(), SetFormatName(), NumericTextCtrl::SetFormatName(), SelectionBar::SetSelectionFormat(), and TimeDialog::TransferDataToWindow().

Here is the caller graph for this function:

◆ GetBuiltinFormat() [2/2]

auto NumericConverter::GetBuiltinFormat ( const NumericFormatSymbol name)

Definition at line 1217 of file NumericTextCtrl.cpp.

1219{
1220 int ndx =
1222 BuiltinFormatString{ name, {} } )
1224 if (ndx == (int)mNBuiltins)
1225 ndx = mDefaultNdx;
1226
1227 return GetBuiltinFormat(ndx);
1228}
const TranslatableString name
Definition: Distortion.cpp:82
FormatStrings GetBuiltinFormat(const int index)
struct to hold a formatting control string and its user facing name Used in an array to hold the buil...

References name.

◆ GetBuiltinName()

NumericFormatSymbol NumericConverter::GetBuiltinName ( const int  index)

Definition at line 1201 of file NumericTextCtrl.cpp.

1202{
1203 if (index >= 0 && index < GetNumBuiltins())
1204 return mBuiltinFormatStrings[index].name;
1205
1206 return {};
1207}

References GetNumBuiltins(), mBuiltinFormatStrings, and BuiltinFormatString::name.

Referenced by NumericTextCtrl::OnContext(), and TimeToolBar::OnUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFormatIndex()

int NumericConverter::GetFormatIndex ( )

Definition at line 1180 of file NumericTextCtrl.cpp.

1181{
1182 // int ndx = 1;
1183 int ndx = std::min(1, GetNumBuiltins() - 1);
1184 int i;
1185
1186 for (i = 0; i < GetNumBuiltins(); i++) {
1187 if (mFormatString == GetBuiltinFormat(i)) {
1188 ndx = i;
1189 break;
1190 }
1191 }
1192
1193 return ndx;
1194}
FormatStrings mFormatString

References GetBuiltinFormat(), GetNumBuiltins(), mFormatString, and min().

Referenced by TimeToolBar::SetAudioTimeFormat(), TimeToolBar::SetListener(), and TimeToolBar::UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNumBuiltins()

int NumericConverter::GetNumBuiltins ( )

Definition at line 1196 of file NumericTextCtrl.cpp.

1197{
1198 return mNBuiltins;
1199}

References mNBuiltins.

Referenced by GetBuiltinName(), GetFormatIndex(), and NumericTextCtrl::OnContext().

Here is the caller graph for this function:

◆ GetString()

wxString NumericConverter::GetString ( )

Definition at line 1230 of file NumericTextCtrl.cpp.

1231{
1233
1234 return mValueString;
1235}

References mValueString, and ValueToControls().

Referenced by EffectRepeat::DisplayNewTime(), and NumericRenderer::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetValue()

double NumericConverter::GetValue ( )

◆ HertzFormat()

NumericFormatSymbol NumericConverter::HertzFormat ( )
static

Definition at line 701 of file NumericTextCtrl.cpp.

702{ return FrequencyConverterFormats_[0].name; }
static const BuiltinFormatString FrequencyConverterFormats_[]
array of formats the control knows about internally array of string pairs for name of the format and ...

References anonymous_namespace{NumericTextCtrl.cpp}::FrequencyConverterFormats_, and BuiltinFormatString::name.

Referenced by Grid::Grid().

Here is the caller graph for this function:

◆ HoursMinsSecondsFormat()

NumericFormatSymbol NumericConverter::HoursMinsSecondsFormat ( )
static

Definition at line 696 of file NumericTextCtrl.cpp.

697{ return TimeConverterFormats_[1].name; }

References BuiltinFormatString::name, and anonymous_namespace{NumericTextCtrl.cpp}::TimeConverterFormats_.

Referenced by Effect::GetSelectionFormat(), and TimeToolBar::SetToDefaultSize().

Here is the caller graph for this function:

◆ HundredthsFormat()

NumericFormatSymbol NumericConverter::HundredthsFormat ( )
static

Definition at line 698 of file NumericTextCtrl.cpp.

699{ return TimeConverterFormats_[3].name; }

References BuiltinFormatString::name, and anonymous_namespace{NumericTextCtrl.cpp}::TimeConverterFormats_.

Referenced by ContrastDialog::ContrastDialog().

Here is the caller graph for this function:

◆ Increment()

void NumericConverter::Increment ( )

Definition at line 1237 of file NumericTextCtrl.cpp.

1238{
1239 mFocusedDigit = mDigits.size() - 1;
1240 Adjust(1, 1);
1241}

References Adjust(), mDigits, and mFocusedDigit.

Referenced by anonymous_namespace{SelectMenus.cpp}::GridMove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LookupFormat()

NumericFormatSymbol NumericConverter::LookupFormat ( Type  type,
const wxString &  id 
)
static

Definition at line 704 of file NumericTextCtrl.cpp.

705{
706 if (id.empty()) {
707 if (type == TIME)
708 return DefaultSelectionFormat();
709 else
710 return ChooseBuiltinFormatStrings(type)[0].name;
711 }
712 else {
715 auto iter = std::find( begin, end, BuiltinFormatString{ id, {} } );
716 if (iter == end)
717 iter = begin;
718 return iter->name;
719 }
720}
int id
static NumericFormatSymbol DefaultSelectionFormat()
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), anonymous_namespace{NumericTextCtrl.cpp}::ChooseBuiltinFormatStrings(), anonymous_namespace{NumericTextCtrl.cpp}::ChooseNBuiltinFormatStrings(), DefaultSelectionFormat(), PackedArray::end(), id, BuiltinFormatString::name, and TIME.

Referenced by AUPImportFileHandle::Import(), LabelDialog::OnFreqUpdate(), EffectChangeSpeed::OnTimeCtrlUpdate(), LabelDialog::OnUpdate(), SelectionBar::OnUpdate(), EffectChangeSpeed::PopulateOrExchange(), and SelectionBar::UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseFormatString()

void NumericConverter::ParseFormatString ( const TranslatableString untranslatedFormat)
private

Definition at line 753 of file NumericTextCtrl.cpp.

755{
756 auto format = untranslatedFormat.Translation();
757
758 mPrefix = wxT("");
759 mFields.clear();
760 mDigits.clear();
761 mScalingFactor = 1.0;
762
763 // We will change inFrac to true when we hit our first decimal point.
764 bool inFrac = false;
765 int fracMult = 1;
766 int numWholeFields = 0;
767 int numFracFields = 0;
768 wxString numStr;
769 wxString delimStr;
770 unsigned int i;
771
772 mNtscDrop = false;
773 for(i=0; i<format.length(); i++) {
774 bool handleDelim = false;
775 bool handleNum = false;
776
777 if (format[i] == '|') {
778 wxString remainder = format.Right(format.length() - i - 1);
779 // For languages which use , as a separator.
780 remainder.Replace(wxT(","), wxT("."));
781
782 if (remainder == wxT("#"))
784 else if (remainder == wxT("N")) {
785 mNtscDrop = true;
786 }
787 else
788 // Use the C locale here for string to number.
789 // Translations are often incomplete.
790 // We can't rely on the correct ',' or '.' in the
791 // translation, so we work based on '.' for decimal point.
792 remainder.ToCDouble(&mScalingFactor);
793 i = format.length()-1; // force break out of loop
794 if (!delimStr.empty())
795 handleDelim = true;
796 if (!numStr.empty())
797 handleNum = true;
798 }
799 else if ((format[i] >= '0' && format[i] <='9') ||
800 format[i] == wxT('*') || format[i] == wxT('#')) {
801 numStr += format[i];
802 if (!delimStr.empty())
803 handleDelim = true;
804 }
805 else {
806 delimStr += format[i];
807 if (!numStr.empty())
808 handleNum = true;
809 }
810
811 if (i == format.length() - 1) {
812 if (!numStr.empty())
813 handleNum = true;
814 if (!delimStr.empty())
815 handleDelim = true;
816 }
817
818 if (handleNum) {
819 bool zeropad = false;
820 long range = 0;
821
822 if (numStr.Right(1) == wxT("#"))
823 range = (long int)mSampleRate;
824 else if (numStr.Right(1) != wxT("*")) {
825 numStr.ToLong(&range);
826 }
827 if (numStr.GetChar(0)=='0' && numStr.length()>1)
828 zeropad = true;
829
830 // Hack: always zeropad
831 zeropad = true;
832
833 if (inFrac) {
834 int base = fracMult * range;
835 mFields.push_back(NumericField(inFrac, base, range, zeropad));
836 fracMult *= range;
837 numFracFields++;
838 }
839 else {
840 unsigned int j;
841 for(j=0; j<mFields.size(); j++)
842 mFields[j].base *= range;
843 mFields.push_back(NumericField(inFrac, 1, range, zeropad));
844 numWholeFields++;
845 }
846 numStr = wxT("");
847 }
848
849 if (handleDelim) {
850 bool goToFrac = false;
851
852 if (!inFrac) {
853 wxChar delim = delimStr[delimStr.length()-1];
854 if (delim=='<' || delim=='>') {
855 goToFrac = true;
856 if (delimStr.length() > 1)
857 delimStr = delimStr.BeforeLast(delim);
858 }
859 }
860
861 if (inFrac) {
862 if (numFracFields == 0) {
863 // Should never happen
864 return;
865 }
866 if (handleNum && numFracFields > 1)
867 mFields[mFields.size()-2].label = delimStr;
868 else
869 mFields[mFields.size()-1].label = delimStr;
870 }
871 else {
872 if (numWholeFields == 0)
873 mPrefix = delimStr;
874 else {
875 delimStr.Replace(wxT("<"), wxT(","));
876 delimStr.Replace(wxT(">"), wxT("."));
877 mFields[numWholeFields-1].label = delimStr;
878 }
879 }
880
881 if (goToFrac)
882 inFrac = true;
883 delimStr = wxT("");
884 }
885 }
886
887 for(i = 0; i < mFields.size(); i++) {
888 mFields[i].CreateDigitFormatStr();
889 }
890
891 int pos = 0;
892 int j;
893 mValueMask = wxT("");
894 mValueTemplate = wxT("");
895
897 for(j=0; j<(int)mPrefix.length(); j++)
898 mValueMask += wxT(".");
899 pos += mPrefix.length();
900
901 for(i = 0; i < mFields.size(); i++) {
902 mFields[i].pos = pos;
903
904 for(j=0; j<mFields[i].digits; j++) {
905 mDigits.push_back(DigitInfo(i, j, pos, wxRect()));
906 mValueTemplate += wxT("0");
907 mValueMask += wxT("0");
908 pos++;
909 }
910
911 pos += mFields[i].label.length();
912 mValueTemplate += mFields[i].label;
913 for(j=0; j<(int)mFields[i].label.length(); j++)
914 mValueMask += wxT(".");
915 }
916}
wxT("CloseDown"))
int format
Definition: ExportPCM.cpp:56
TranslatableString label
Definition: TagsEditor.cpp:163
DigitInfo is a class used in NumericTextCtrl.
NumericField is a class used in NumericTextCtrl.
wxString Translation() const

References format, label, mDigits, mFields, mNtscDrop, mPrefix, mSampleRate, mScalingFactor, mValueMask, mValueTemplate, TranslatableString::Translation(), and wxT().

Referenced by SetFormatString(), and SetSampleRate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintDebugInfo()

void NumericConverter::PrintDebugInfo ( )

Definition at line 918 of file NumericTextCtrl.cpp.

919{
920 unsigned int i;
921
922 wxPrintf("%s", (const char *)mPrefix.mb_str());
923
924 for(i = 0; i < mFields.size(); i++) {
925 if (mFields[i].frac) {
926 wxPrintf("(t * %d) %% %d '%s' ",
927 mFields[i].base,
928 mFields[i].range,
929 (const char *)mFields[i].label.mb_str());
930
931 }
932 else {
933 wxPrintf("(t / %d) %% %d '%s' ",
934 mFields[i].base,
935 mFields[i].range,
936 (const char *)mFields[i].label.mb_str());
937 }
938 }
939
940 wxPrintf("\n");
941}

References label, mFields, and mPrefix.

◆ ResetMaxValue()

void NumericConverter::ResetMaxValue ( )

Definition at line 1169 of file NumericTextCtrl.cpp.

1170{
1171 mMaxValue = std::numeric_limits<double>::max();
1172}

References mMaxValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ ResetMinValue()

void NumericConverter::ResetMinValue ( )

Definition at line 1154 of file NumericTextCtrl.cpp.

1155{
1156 mMinValue = 0.0;
1157}

References mMinValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ SecondsFormat()

NumericFormatSymbol NumericConverter::SecondsFormat ( )
static

Definition at line 694 of file NumericTextCtrl.cpp.

695{ return TimeConverterFormats_[0].name; }

References BuiltinFormatString::name, and anonymous_namespace{NumericTextCtrl.cpp}::TimeConverterFormats_.

Referenced by Grid::Grid().

Here is the caller graph for this function:

◆ SetFormatName()

bool NumericConverter::SetFormatName ( const NumericFormatSymbol formatName)

Definition at line 1111 of file NumericTextCtrl.cpp.

1112{
1113 return
1114 SetFormatString(GetBuiltinFormat(formatName));
1115}
bool SetFormatString(const FormatStrings &formatString)

References GetBuiltinFormat(), and SetFormatString().

Referenced by NumericConverter(), and SnapManager::Reinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFormatString()

bool NumericConverter::SetFormatString ( const FormatStrings formatString)

Definition at line 1117 of file NumericTextCtrl.cpp.

1118{
1119 if (mFormatString != formatString) {
1120 mFormatString = formatString;
1124 return true;
1125 }
1126 else
1127 return false;
1128}
void ParseFormatString(const TranslatableString &untranslatedFormat)

References ControlsToValue(), NumericConverter::FormatStrings::formatStr, mFormatString, ParseFormatString(), and ValueToControls().

Referenced by SetFormatName(), and NumericTextCtrl::SetFormatString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetMaxValue()

void NumericConverter::SetMaxValue ( double  maxValue)

Definition at line 1159 of file NumericTextCtrl.cpp.

1160{
1161 mMaxValue = maxValue;
1162 if (mMinValue > maxValue) {
1163 mMinValue = maxValue;
1164 }
1165 if (mValue > maxValue)
1166 SetValue(maxValue);
1167}

References mMaxValue, mMinValue, mValue, and SetValue().

Here is the call graph for this function:

◆ SetMinValue()

void NumericConverter::SetMinValue ( double  minValue)

Definition at line 1145 of file NumericTextCtrl.cpp.

1146{
1147 mMinValue = minValue;
1148 if (mMaxValue < minValue)
1149 mMaxValue = minValue;
1150 if (mValue < minValue)
1151 SetValue(minValue);
1152}

References mMaxValue, mMinValue, mValue, and SetValue().

Here is the call graph for this function:

◆ SetSampleRate()

void NumericConverter::SetSampleRate ( double  sampleRate)

Definition at line 1130 of file NumericTextCtrl.cpp.

1131{
1132 mSampleRate = sampleRate;
1136}

References ControlsToValue(), NumericConverter::FormatStrings::formatStr, mFormatString, mSampleRate, ParseFormatString(), and ValueToControls().

Referenced by NumericConverter(), SnapManager::Reinit(), and NumericTextCtrl::SetSampleRate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetValue()

void NumericConverter::SetValue ( double  newValue)

Definition at line 1138 of file NumericTextCtrl.cpp.

1139{
1140 mValue = newValue;
1143}

References ControlsToValue(), mValue, and ValueToControls().

Referenced by SnapManager::CondListAdd(), EffectRepeat::DisplayNewTime(), anonymous_namespace{SelectMenus.cpp}::GridMove(), NumericConverter(), SetMaxValue(), SetMinValue(), and NumericTextCtrl::SetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TimeAndSampleFormat()

NumericFormatSymbol NumericConverter::TimeAndSampleFormat ( )
static

Definition at line 692 of file NumericTextCtrl.cpp.

693{ return TimeConverterFormats_[5].name; }

References BuiltinFormatString::name, and anonymous_namespace{NumericTextCtrl.cpp}::TimeConverterFormats_.

Referenced by EffectBase::DoEffect().

Here is the caller graph for this function:

◆ ValueToControls() [1/2]

void NumericConverter::ValueToControls ( )
virtual

Reimplemented in NumericTextCtrl.

Definition at line 949 of file NumericTextCtrl.cpp.

950{
952}

References mValue, and ValueToControls().

Referenced by Adjust(), GetString(), SetFormatString(), SetSampleRate(), SetValue(), SnapManager::Snap(), ProjectSelectionManager::SnapSelection(), ValueToControls(), and NumericTextCtrl::ValueToControls().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ValueToControls() [2/2]

void NumericConverter::ValueToControls ( double  rawValue,
bool  nearest = true 
)
virtual

Definition at line 954 of file NumericTextCtrl.cpp.

955{
956 //rawValue = 4.9995f; Only for testing!
957 if (mType == TIME)
958 rawValue =
959 floor(rawValue * mSampleRate + (nearest ? 0.5f : 0.0f))
960 / mSampleRate; // put on a sample
961 double theValue =
962 rawValue * mScalingFactor
963 // PRL: what WAS this .000001 for? Nobody could explain.
964 // + .000001
965 ;
966 sampleCount t_int;
967 bool round = true;
968 // We round on the last field. If we have a fractional field we round using it.
969 // Otherwise we round to nearest integer.
970 for(unsigned int i = 0; i < mFields.size(); i++) {
971 if (mFields[i].frac)
972 round = false;
973 }
974 if (theValue < 0)
975 t_int = -1;
976 else if(round)
977 t_int = sampleCount(theValue + (nearest ? 0.5f : 0.0f));
978 else
979 {
980 wxASSERT( mFields.back().frac );
981 theValue += (nearest ? 0.5f : 0.0f) / mFields.back().base;
982 t_int = sampleCount(theValue);
983 }
984 double t_frac;
985 if (theValue < 0)
986 t_frac = -1;
987 else
988 t_frac = (theValue - t_int.as_double() );
989 unsigned int i;
990 int tenMins;
991 int mins;
992 int addMins;
993 int secs;
994 int frames;
995
997
998 if(mNtscDrop && theValue >= 0) {
999 frames = (int)(theValue*30./1.001 + (nearest ? 0.5f : 0.0f));
1000 tenMins = frames/17982;
1001 frames -= tenMins*17982;
1002 mins = tenMins * 10;
1003 if(frames >= 1800) {
1004 frames -= 1800;
1005 mins++;
1006 addMins = frames/1798;
1007 frames -= addMins*1798;
1008 mins += addMins;
1009 secs = frames/30;
1010 frames -= secs*30;
1011 frames += 2;
1012 if( frames >= 30 ) {
1013 secs++;
1014 frames -= 30;
1015 }
1016 }
1017 else {
1018 secs = frames/30;
1019 frames -= secs*30;
1020 }
1021 t_int = mins * 60 + secs;
1022 t_frac = frames / 30.;
1023 }
1024
1025 for(i = 0; i < mFields.size(); i++) {
1026 long long value = -1;
1027
1028 if (mFields[i].frac) {
1029 // JKC: This old code looks bogus to me.
1030 // The rounding is not propagating to earlier fields in the frac case.
1031 //value = (int)(t_frac * mFields[i].base + 0.5); // +0.5 as rounding required
1032 // I did the rounding earlier.
1033 if (t_frac >= 0)
1034 value = t_frac * mFields[i].base;
1035 // JKC: TODO: Find out what the range is supposed to do.
1036 // It looks bogus too.
1037 //if (mFields[i].range > 0)
1038 // value = value % mFields[i].range;
1039 }
1040 else {
1041 if (t_int >= 0) {
1042 value = t_int.as_long_long() / mFields[i].base;
1043 if (mFields[i].range > 0)
1044 value = value % mFields[i].range;
1045 }
1046 }
1047
1048 wxString field;
1049 if (value < 0) {
1050 for (int ii = 0; ii < mFields[i].digits; ++ii)
1051 field += wxT("-");
1052 }
1053 else
1054 field = wxString::Format(mFields[i].formatStr, (int) value);
1056 mValueString += mFields[i].label;
1057 }
1058}
#define field(n, t)
Definition: ImportAUP.cpp:167
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
long long as_long_long() const
Definition: SampleCount.h:48
double as_double() const
Definition: SampleCount.h:46
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References sampleCount::as_double(), sampleCount::as_long_long(), field, mFields, mNtscDrop, mPrefix, mSampleRate, mScalingFactor, mType, mValueString, fast_float::round(), TIME, and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ mBuiltinFormatStrings

const BuiltinFormatString* NumericConverter::mBuiltinFormatStrings
protected

Definition at line 165 of file NumericTextCtrl.h.

Referenced by GetBuiltinName().

◆ mDefaultNdx

int NumericConverter::mDefaultNdx
protected

Definition at line 167 of file NumericTextCtrl.h.

Referenced by NumericConverter().

◆ mDigits

std::vector<DigitInfo> NumericConverter::mDigits
protected

◆ mFields

std::vector<NumericField> NumericConverter::mFields
protected

◆ mFocusedDigit

int NumericConverter::mFocusedDigit
protected

◆ mFormatString

FormatStrings NumericConverter::mFormatString
protected

◆ mInvalidValue

double NumericConverter::mInvalidValue
protected

◆ mMaxValue

double NumericConverter::mMaxValue
protected

◆ mMinValue

double NumericConverter::mMinValue
protected

◆ mNBuiltins

const size_t NumericConverter::mNBuiltins
protected

Definition at line 166 of file NumericTextCtrl.h.

Referenced by GetNumBuiltins().

◆ mNtscDrop

bool NumericConverter::mNtscDrop
protected

◆ mPrefix

wxString NumericConverter::mPrefix
protected

◆ mSampleRate

double NumericConverter::mSampleRate
protected

◆ mScalingFactor

double NumericConverter::mScalingFactor
protected

◆ mType

Type NumericConverter::mType
protected

Definition at line 141 of file NumericTextCtrl.h.

Referenced by NumericConverter(), and ValueToControls().

◆ mValue

double NumericConverter::mValue
protected

◆ mValueMask

wxString NumericConverter::mValueMask
protected

Definition at line 154 of file NumericTextCtrl.h.

Referenced by ParseFormatString().

◆ mValueString

wxString NumericConverter::mValueString
protected

◆ mValueTemplate

wxString NumericConverter::mValueTemplate
protected

Definition at line 153 of file NumericTextCtrl.h.

Referenced by ParseFormatString().


The documentation for this class was generated from the following files: