Audacity  3.0.3
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.
54  FREQUENCY,
55  BANDWIDTH,
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 720 of file NumericTextCtrl.cpp.

726 {
727  ResetMinValue();
728  ResetMaxValue();
729  mInvalidValue = -1.0;
730 
731  mDefaultNdx = 0;
732 
733  mType = type;
734 
735  if (type == NumericConverter::TIME )
736  mDefaultNdx = 4; // Default to "hh:mm:ss + milliseconds".
737 
738  mScalingFactor = 1.0f;
739  mSampleRate = 1.0f;
740  mNtscDrop = false;
741 
742  mFocusedDigit = 0;
743 
744  mValue = value; // used in SetSampleRate, reassigned later
745 
746  SetSampleRate(sampleRate);
747  SetFormatName(formatName);
748  SetValue(value); // mValue got overridden to -1 in ControlsToValue(), reassign
749 }

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 943 of file NumericTextCtrl.cpp.

944 {
945 }

Member Function Documentation

◆ Adjust()

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

Definition at line 1247 of file NumericTextCtrl.cpp.

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

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 1058 of file NumericTextCtrl.cpp.

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

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 1241 of file NumericTextCtrl.cpp.

1242 {
1243  mFocusedDigit = mDigits.size() - 1;
1244  Adjust(1, -1);
1245 }

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 688 of file NumericTextCtrl.cpp.

689 { return TimeConverterFormats_[4].name; }

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

Referenced by Effect::DoEffect(), EffectChangeSpeed::EffectChangeSpeed(), EffectChangeSpeed::LoadFactoryDefaults(), and LookupFormat().

Here is the caller graph for this function:

◆ GetBuiltinFormat() [1/2]

auto NumericConverter::GetBuiltinFormat ( const int  index)

Definition at line 1207 of file NumericTextCtrl.cpp.

1208 {
1209  if (index >= 0 && index < GetNumBuiltins())
1210  return mBuiltinFormatStrings[index].formatStrings;
1211 
1212  return {};
1213 }

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 1215 of file NumericTextCtrl.cpp.

1217 {
1218  int ndx =
1220  BuiltinFormatString{ name, {} } )
1222  if (ndx == (int)mNBuiltins)
1223  ndx = mDefaultNdx;
1224 
1225  return GetBuiltinFormat(ndx);
1226 }

References name.

◆ GetBuiltinName()

NumericFormatSymbol NumericConverter::GetBuiltinName ( const int  index)

Definition at line 1199 of file NumericTextCtrl.cpp.

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

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 1178 of file NumericTextCtrl.cpp.

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

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 1194 of file NumericTextCtrl.cpp.

1195 {
1196  return mNBuiltins;
1197 }

References mNBuiltins.

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

Here is the caller graph for this function:

◆ GetString()

wxString NumericConverter::GetString ( )

Definition at line 1228 of file NumericTextCtrl.cpp.

1229 {
1230  ValueToControls();
1231 
1232  return mValueString;
1233 }

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 699 of file NumericTextCtrl.cpp.

700 { return FrequencyConverterFormats_[0].name; }

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 694 of file NumericTextCtrl.cpp.

695 { 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 696 of file NumericTextCtrl.cpp.

697 { 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 1235 of file NumericTextCtrl.cpp.

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

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 702 of file NumericTextCtrl.cpp.

703 {
704  if (id.empty()) {
705  if (type == TIME)
706  return DefaultSelectionFormat();
707  else
708  return ChooseBuiltinFormatStrings(type)[0].name;
709  }
710  else {
711  auto begin = ChooseBuiltinFormatStrings(type);
712  auto end = begin + ChooseNBuiltinFormatStrings(type);
713  auto iter = std::find( begin, end, BuiltinFormatString{ id, {} } );
714  if (iter == end)
715  iter = begin;
716  return iter->name;
717  }
718 }

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

Referenced by AUPImportFileHandle::Import(), LabelDialog::OnFreqUpdate(), EffectChangeSpeed::OnTimeCtrlUpdate(), LabelDialog::OnUpdate(), SelectionBar::OnUpdate(), EffectChangeSpeed::PopulateOrExchange(), EffectChangeSpeed::Startup(), 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 751 of file NumericTextCtrl.cpp.

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

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

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 916 of file NumericTextCtrl.cpp.

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

References label, mFields, and mPrefix.

◆ ResetMaxValue()

void NumericConverter::ResetMaxValue ( )

Definition at line 1167 of file NumericTextCtrl.cpp.

1168 {
1169  mMaxValue = std::numeric_limits<double>::max();
1170 }

References mMaxValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ ResetMinValue()

void NumericConverter::ResetMinValue ( )

Definition at line 1152 of file NumericTextCtrl.cpp.

1153 {
1154  mMinValue = 0.0;
1155 }

References mMinValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ SecondsFormat()

NumericFormatSymbol NumericConverter::SecondsFormat ( )
static

Definition at line 692 of file NumericTextCtrl.cpp.

693 { 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 1109 of file NumericTextCtrl.cpp.

1110 {
1111  return
1112  SetFormatString(GetBuiltinFormat(formatName));
1113 }

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 1115 of file NumericTextCtrl.cpp.

1116 {
1117  if (mFormatString != formatString) {
1118  mFormatString = formatString;
1120  ValueToControls();
1121  ControlsToValue();
1122  return true;
1123  }
1124  else
1125  return false;
1126 }

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 1157 of file NumericTextCtrl.cpp.

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

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

Here is the call graph for this function:

◆ SetMinValue()

void NumericConverter::SetMinValue ( double  minValue)

Definition at line 1143 of file NumericTextCtrl.cpp.

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

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

Here is the call graph for this function:

◆ SetSampleRate()

void NumericConverter::SetSampleRate ( double  sampleRate)

Definition at line 1128 of file NumericTextCtrl.cpp.

1129 {
1130  mSampleRate = sampleRate;
1132  ValueToControls();
1133  ControlsToValue();
1134 }

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 1136 of file NumericTextCtrl.cpp.

1137 {
1138  mValue = newValue;
1139  ValueToControls();
1140  ControlsToValue();
1141 }

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 690 of file NumericTextCtrl.cpp.

691 { return TimeConverterFormats_[5].name; }

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

Referenced by Effect::DoEffect().

Here is the caller graph for this function:

◆ ValueToControls() [1/2]

void NumericConverter::ValueToControls ( )
virtual

Reimplemented in NumericTextCtrl.

Definition at line 947 of file NumericTextCtrl.cpp.

948 {
950 }

References mValue.

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

Here is the caller graph for this function:

◆ ValueToControls() [2/2]

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

Definition at line 952 of file NumericTextCtrl.cpp.

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

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

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:
field
#define field(n, t)
Definition: ImportAUP.cpp:167
NumericConverter::SetFormatString
bool SetFormatString(const FormatStrings &formatString)
Definition: NumericTextCtrl.cpp:1115
DigitInfo
DigitInfo is a class used in NumericTextCtrl.
Definition: NumericTextCtrl.cpp:347
NumericConverter::ResetMaxValue
void ResetMaxValue()
Definition: NumericTextCtrl.cpp:1167
NumericConverter::SetFormatName
bool SetFormatName(const NumericFormatSymbol &formatName)
Definition: NumericTextCtrl.cpp:1109
NumericField
NumericField is a class used in NumericTextCtrl.
Definition: NumericTextCtrl.cpp:301
anonymous_namespace{NumericTextCtrl.cpp}::ChooseNBuiltinFormatStrings
size_t ChooseNBuiltinFormatStrings(NumericConverter::Type type)
Definition: NumericTextCtrl.cpp:669
BuiltinFormatString
struct to hold a formatting control string and its user facing name Used in an array to hold the buil...
Definition: NumericTextCtrl.cpp:286
NumericConverter::mFields
std::vector< NumericField > mFields
Definition: NumericTextCtrl.h:151
NumericConverter::mScalingFactor
double mScalingFactor
Definition: NumericTextCtrl.h:158
NumericConverter::ATIME
@ ATIME
Definition: NumericTextCtrl.h:53
NumericConverter::mNBuiltins
const size_t mNBuiltins
Definition: NumericTextCtrl.h:166
NumericConverter::mValue
double mValue
Definition: NumericTextCtrl.h:143
NumericConverter::mValueMask
wxString mValueMask
Definition: NumericTextCtrl.h:154
NumericConverter::ValueToControls
virtual void ValueToControls()
Definition: NumericTextCtrl.cpp:947
NumericConverter::mDigits
std::vector< DigitInfo > mDigits
Definition: NumericTextCtrl.h:163
NumericConverter::mBuiltinFormatStrings
const BuiltinFormatString * mBuiltinFormatStrings
Definition: NumericTextCtrl.h:165
NumericConverter::mPrefix
wxString mPrefix
Definition: NumericTextCtrl.h:152
NumericConverter::BANDWIDTH
@ BANDWIDTH
Definition: NumericTextCtrl.h:55
NumericConverter::FormatStrings::formatStr
TranslatableString formatStr
Definition: NumericTextCtrl.h:59
NumericConverter::mNtscDrop
bool mNtscDrop
Definition: NumericTextCtrl.h:160
NumericConverter::mInvalidValue
double mInvalidValue
Definition: NumericTextCtrl.h:147
NumericConverter::DefaultSelectionFormat
static NumericFormatSymbol DefaultSelectionFormat()
Definition: NumericTextCtrl.cpp:688
NumericConverter::mSampleRate
double mSampleRate
Definition: NumericTextCtrl.h:159
NumericConverter::ControlsToValue
virtual void ControlsToValue()
Definition: NumericTextCtrl.cpp:1058
sampleCount::as_double
double as_double() const
Definition: SampleCount.h:45
NumericConverter::GetBuiltinFormat
FormatStrings GetBuiltinFormat(const int index)
Definition: NumericTextCtrl.cpp:1207
label
TranslatableString label
Definition: Tags.cpp:756
sampleCount::as_long_long
long long as_long_long() const
Definition: SampleCount.h:47
NumericConverter::ParseFormatString
void ParseFormatString(const TranslatableString &untranslatedFormat)
Definition: NumericTextCtrl.cpp:751
NumericConverter::mType
Type mType
Definition: NumericTextCtrl.h:141
NumericConverter::mMinValue
double mMinValue
Definition: NumericTextCtrl.h:145
name
const TranslatableString name
Definition: Distortion.cpp:98
anonymous_namespace{NumericTextCtrl.cpp}::TimeConverterFormats_
static const BuiltinFormatString TimeConverterFormats_[]
array of formats the control knows about internally array of string pairs for name of the format and ...
Definition: NumericTextCtrl.cpp:368
NumericConverter::TIME
@ TIME
Definition: NumericTextCtrl.h:52
format
int format
Definition: ExportPCM.cpp:56
NumericConverter::GetNumBuiltins
int GetNumBuiltins()
Definition: NumericTextCtrl.cpp:1194
NumericConverter::mMaxValue
double mMaxValue
Definition: NumericTextCtrl.h:146
NumericConverter::FREQUENCY
@ FREQUENCY
Definition: NumericTextCtrl.h:54
id
int id
Definition: WaveTrackControls.cpp:591
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
NumericConverter::mDefaultNdx
int mDefaultNdx
Definition: NumericTextCtrl.h:167
NumericConverter::mFormatString
FormatStrings mFormatString
Definition: NumericTextCtrl.h:149
NumericConverter::mValueTemplate
wxString mValueTemplate
Definition: NumericTextCtrl.h:153
NumericConverter::SetValue
void SetValue(double newValue)
Definition: NumericTextCtrl.cpp:1136
sampleCount
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:18
anonymous_namespace{NumericTextCtrl.cpp}::ChooseBuiltinFormatStrings
const BuiltinFormatString * ChooseBuiltinFormatStrings(NumericConverter::Type type)
Definition: NumericTextCtrl.cpp:655
NumericConverter::Adjust
void Adjust(int steps, int dir)
Definition: NumericTextCtrl.cpp:1247
BuiltinFormatString::formatStrings
NumericConverter::FormatStrings formatStrings
Definition: NumericTextCtrl.cpp:288
NumericConverter::ResetMinValue
void ResetMinValue()
Definition: NumericTextCtrl.cpp:1152
NumericConverter::mFocusedDigit
int mFocusedDigit
Definition: NumericTextCtrl.h:162
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
NumericConverter::SetSampleRate
void SetSampleRate(double sampleRate)
Definition: NumericTextCtrl.cpp:1128
NumericConverter::mValueString
wxString mValueString
Definition: NumericTextCtrl.h:156
anonymous_namespace{NumericTextCtrl.cpp}::FrequencyConverterFormats_
static const BuiltinFormatString FrequencyConverterFormats_[]
array of formats the control knows about internally array of string pairs for name of the format and ...
Definition: NumericTextCtrl.cpp:576
BuiltinFormatString::name
NumericFormatSymbol name
Definition: NumericTextCtrl.cpp:287