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)
 
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 46 of file NumericTextCtrl.h.

Member Enumeration Documentation

◆ Type

Enumerator
TIME 
ATIME 
FREQUENCY 
BANDWIDTH 

Definition at line 50 of file NumericTextCtrl.h.

50  {
51  TIME,
52  ATIME, // for Audio time control.
53  FREQUENCY,
54  BANDWIDTH,
55  };

Constructor & Destructor Documentation

◆ NumericConverter()

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()

NumericConverter::~NumericConverter ( )
virtual

Definition at line 941 of file NumericTextCtrl.cpp.

942 {
943 }

Member Function Documentation

◆ Adjust()

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

Definition at line 1245 of file NumericTextCtrl.cpp.

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

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

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

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

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

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

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

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

1215 {
1216  int ndx =
1218  BuiltinFormatString{ name, {} } )
1220  if (ndx == (int)mNBuiltins)
1221  ndx = mDefaultNdx;
1222 
1223  return GetBuiltinFormat(ndx);
1224 }

References name.

◆ GetBuiltinName()

NumericFormatSymbol NumericConverter::GetBuiltinName ( const int  index)

Definition at line 1197 of file NumericTextCtrl.cpp.

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

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

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

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

1193 {
1194  return mNBuiltins;
1195 }

References mNBuiltins.

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

Here is the caller graph for this function:

◆ GetString()

wxString NumericConverter::GetString ( )

Definition at line 1226 of file NumericTextCtrl.cpp.

1227 {
1228  ValueToControls();
1229 
1230  return mValueString;
1231 }

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

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

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 ProjectFileIO::HandleXMLTag(), 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 1165 of file NumericTextCtrl.cpp.

1166 {
1167  mMaxValue = std::numeric_limits<double>::max();
1168 }

References mMaxValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ ResetMinValue()

void NumericConverter::ResetMinValue ( )

Definition at line 1150 of file NumericTextCtrl.cpp.

1151 {
1152  mMinValue = 0.0;
1153 }

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

1108 {
1109  return
1110  SetFormatString(GetBuiltinFormat(formatName));
1111 }

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

1114 {
1115  if (mFormatString != formatString) {
1116  mFormatString = formatString;
1118  ValueToControls();
1119  ControlsToValue();
1120  return true;
1121  }
1122  else
1123  return false;
1124 }

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

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

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

Here is the call graph for this function:

◆ SetMinValue()

void NumericConverter::SetMinValue ( double  minValue)

Definition at line 1141 of file NumericTextCtrl.cpp.

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

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

Here is the call graph for this function:

◆ SetSampleRate()

void NumericConverter::SetSampleRate ( double  sampleRate)

Definition at line 1126 of file NumericTextCtrl.cpp.

1127 {
1128  mSampleRate = sampleRate;
1130  ValueToControls();
1131  ControlsToValue();
1132 }

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

1135 {
1136  mValue = newValue;
1137  ValueToControls();
1138  ControlsToValue();
1139 }

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

946 {
948 }

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

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

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 163 of file NumericTextCtrl.h.

Referenced by GetBuiltinName().

◆ mDefaultNdx

int NumericConverter::mDefaultNdx
protected

Definition at line 165 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 164 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 139 of file NumericTextCtrl.h.

Referenced by NumericConverter(), and ValueToControls().

◆ mValue

double NumericConverter::mValue
protected

◆ mValueMask

wxString NumericConverter::mValueMask
protected

Definition at line 152 of file NumericTextCtrl.h.

Referenced by ParseFormatString().

◆ mValueString

wxString NumericConverter::mValueString
protected

◆ mValueTemplate

wxString NumericConverter::mValueTemplate
protected

Definition at line 151 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:165
NumericConverter::SetFormatString
bool SetFormatString(const FormatStrings &formatString)
Definition: NumericTextCtrl.cpp:1113
DigitInfo
DigitInfo is a class used in NumericTextCtrl.
Definition: NumericTextCtrl.cpp:347
NumericConverter::ResetMaxValue
void ResetMaxValue()
Definition: NumericTextCtrl.cpp:1165
NumericConverter::SetFormatName
bool SetFormatName(const NumericFormatSymbol &formatName)
Definition: NumericTextCtrl.cpp:1107
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:149
NumericConverter::mScalingFactor
double mScalingFactor
Definition: NumericTextCtrl.h:156
NumericConverter::ATIME
@ ATIME
Definition: NumericTextCtrl.h:52
NumericConverter::mNBuiltins
const size_t mNBuiltins
Definition: NumericTextCtrl.h:164
NumericConverter::mValue
double mValue
Definition: NumericTextCtrl.h:141
NumericConverter::mValueMask
wxString mValueMask
Definition: NumericTextCtrl.h:152
NumericConverter::ValueToControls
virtual void ValueToControls()
Definition: NumericTextCtrl.cpp:945
NumericConverter::mDigits
std::vector< DigitInfo > mDigits
Definition: NumericTextCtrl.h:161
NumericConverter::mBuiltinFormatStrings
const BuiltinFormatString * mBuiltinFormatStrings
Definition: NumericTextCtrl.h:163
NumericConverter::mPrefix
wxString mPrefix
Definition: NumericTextCtrl.h:150
NumericConverter::BANDWIDTH
@ BANDWIDTH
Definition: NumericTextCtrl.h:54
NumericConverter::FormatStrings::formatStr
TranslatableString formatStr
Definition: NumericTextCtrl.h:58
NumericConverter::mNtscDrop
bool mNtscDrop
Definition: NumericTextCtrl.h:158
NumericConverter::mInvalidValue
double mInvalidValue
Definition: NumericTextCtrl.h:145
NumericConverter::DefaultSelectionFormat
static NumericFormatSymbol DefaultSelectionFormat()
Definition: NumericTextCtrl.cpp:688
NumericConverter::mSampleRate
double mSampleRate
Definition: NumericTextCtrl.h:157
NumericConverter::ControlsToValue
virtual void ControlsToValue()
Definition: NumericTextCtrl.cpp:1056
sampleCount::as_double
double as_double() const
Definition: Types.h:608
NumericConverter::GetBuiltinFormat
FormatStrings GetBuiltinFormat(const int index)
Definition: NumericTextCtrl.cpp:1205
label
TranslatableString label
Definition: Tags.cpp:755
sampleCount::as_long_long
long long as_long_long() const
Definition: Types.h:610
NumericConverter::ParseFormatString
void ParseFormatString(const TranslatableString &untranslatedFormat)
Definition: NumericTextCtrl.cpp:751
NumericConverter::mType
Type mType
Definition: NumericTextCtrl.h:139
NumericConverter::mMinValue
double mMinValue
Definition: NumericTextCtrl.h:143
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:51
format
int format
Definition: ExportPCM.cpp:54
NumericConverter::GetNumBuiltins
int GetNumBuiltins()
Definition: NumericTextCtrl.cpp:1192
NumericConverter::mMaxValue
double mMaxValue
Definition: NumericTextCtrl.h:144
NumericConverter::FREQUENCY
@ FREQUENCY
Definition: NumericTextCtrl.h:53
id
int id
Definition: WaveTrackControls.cpp:589
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
NumericConverter::mDefaultNdx
int mDefaultNdx
Definition: NumericTextCtrl.h:165
NumericConverter::mFormatString
FormatStrings mFormatString
Definition: NumericTextCtrl.h:147
NumericConverter::mValueTemplate
wxString mValueTemplate
Definition: NumericTextCtrl.h:151
NumericConverter::SetValue
void SetValue(double newValue)
Definition: NumericTextCtrl.cpp:1134
sampleCount
Definition: Types.h:581
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:1245
BuiltinFormatString::formatStrings
NumericConverter::FormatStrings formatStrings
Definition: NumericTextCtrl.cpp:288
NumericConverter::ResetMinValue
void ResetMinValue()
Definition: NumericTextCtrl.cpp:1150
NumericConverter::mFocusedDigit
int mFocusedDigit
Definition: NumericTextCtrl.h:160
TranslatableString::Translation
wxString Translation() const
Definition: Types.h:337
NumericConverter::SetSampleRate
void SetSampleRate(double sampleRate)
Definition: NumericTextCtrl.cpp:1126
NumericConverter::mValueString
wxString mValueString
Definition: NumericTextCtrl.h:154
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