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 <NumericConverter.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 70 of file NumericConverter.h.

Member Enumeration Documentation

◆ Type

Enumerator
TIME 
ATIME 
FREQUENCY 
BANDWIDTH 

Definition at line 74 of file NumericConverter.h.

74 {
75 TIME,
76 ATIME, // for Audio time control.
79 };

Constructor & Destructor Documentation

◆ NumericConverter() [1/2]

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

Definition at line 601 of file NumericConverter.cpp.

607{
610 mInvalidValue = -1.0;
611
612 mDefaultNdx = 0;
613
614 mType = type;
615
616 if (type == NumericConverter::TIME )
617 mDefaultNdx = 5; // Default to "hh:mm:ss + milliseconds".
618
619 mScalingFactor = 1.0f;
620 mSampleRate = 1.0f;
621 mNtscDrop = false;
622
623 mFocusedDigit = 0;
624
625 mValue = value; // used in SetSampleRate, reassigned later
626
627 SetSampleRate(sampleRate);
628 SetFormatName(formatName);
629 SetValue(value); // mValue got overridden to -1 in ControlsToValue(), reassign
630}
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 824 of file NumericConverter.cpp.

825{
826}

Member Function Documentation

◆ Adjust()

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

Definition at line 1128 of file NumericConverter.cpp.

1129{
1130 // It is possible and "valid" for steps to be zero if a
1131 // high precision device is being used and wxWidgets supports
1132 // reporting a higher precision...Mac wx3 does.
1133 if (steps == 0)
1134 return;
1135
1136 wxASSERT(dir == -1 || dir == 1);
1137 wxASSERT(steps > 0);
1138 if (steps < 0)
1139 steps = -steps;
1140
1141 while (steps != 0)
1142 {
1143 for (size_t i = 0; i < mFields.size(); i++)
1144 {
1145 if ((mDigits[mFocusedDigit].pos >= mFields[i].pos) &&
1146 (mDigits[mFocusedDigit].pos < mFields[i].pos + mFields[i].digits))
1147 { //it's this field
1148 if (!mNtscDrop)
1149 {
1151 }
1152 else
1153 {
1154 mNtscDrop = false;
1156 mNtscDrop = true;
1157 }
1158
1159 if (mValue < 0)
1160 mValue = 0;
1161
1163
1164 double mult = pow(10., mFields[i].digits - (mDigits[mFocusedDigit].pos - mFields[i].pos) - 1);
1165 if (mFields[i].frac)
1166 {
1167 mValue += ((mult / (double)mFields[i].base) * dir);
1168 }
1169 else
1170 {
1171 mValue += ((mult * (double)mFields[i].base) * dir);
1172 }
1173
1174 if (mNtscDrop)
1175 {
1176 if ((mValue - (int)mValue) * 30 < 2)
1177 {
1178 if ((((int)mValue) % 60 == 0) && (((int)mValue) % 600 != 0))
1179 {
1180 mValue = (int)mValue + (dir > 0 ? 2. : -1.) / 30.;
1181 }
1182 }
1183 }
1184
1185 if (mValue < 0.)
1186 {
1187 mValue = 0.;
1188 }
1189
1190 mValue = std::max(mMinValue, std::min(mMaxValue, mValue));
1191
1193
1194 if (!mNtscDrop)
1195 {
1197 }
1198 else
1199 {
1200 mNtscDrop = false;
1202 mNtscDrop = true;
1204 }
1205 break;
1206 }
1207 }
1208 steps--;
1209 }
1210
1212}
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 939 of file NumericConverter.cpp.

940{
941 unsigned int i;
942 double t = 0.0;
943
944 if (mFields.size() > 0 &&
945 mValueString.Mid(mFields[0].pos, 1) == wxChar('-')) {
947 return;
948 }
949
950 for(i = 0; i < mFields.size(); i++) {
951 long val;
952 mFields[i].str = mValueString.Mid(mFields[i].pos,
953 mFields[i].digits);
954 mFields[i].str.ToLong(&val);
955 if (mFields[i].frac)
956 t += (val / (double)mFields[i].base);
957 else
958 t += (val * (double)mFields[i].base);
959 }
960
961 t /= mScalingFactor;
962 if(mNtscDrop) {
963 int t_int = (int)(t + .000000001);
964 double t_frac = (t - t_int);
965 int tenMins = t_int/600;
966 double frames = tenMins*17982;
967 t_int -= tenMins*600;
968 int mins = t_int/60;
969 int addMins = 0;
970 if( mins > 0 ) {
971 frames += 1800;
972 addMins = mins - 1;
973 }
974 frames += addMins * 1798;
975 t_int -= mins*60;
976 if( mins == 0 ) //first min of a block of 10, don't drop frames 0 and 1
977 frames += t_int * 30 + t_frac*30.;
978 else { //drop frames 0 and 1 of first seconds of these minutes
979 if( t_int > 0 )
980 frames += 28 + (t_int-1)*30 + t_frac*30.;
981 else
982 frames += t_frac*30. -2.;
983 }
984 t = frames * 1.001 / 30.;
985 }
986
987 mValue = std::max(mMinValue, std::min(mMaxValue, t));
988}

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 1122 of file NumericConverter.cpp.

1123{
1124 mFocusedDigit = mDigits.size() - 1;
1125 Adjust(1, -1);
1126}
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 569 of file NumericConverter.cpp.

570{ return TimeConverterFormats_[5].name; }
static 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{NumericConverter.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 1088 of file NumericConverter.cpp.

1089{
1090 if (index >= 0 && index < GetNumBuiltins())
1092
1093 return {};
1094}
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 1096 of file NumericConverter.cpp.

1098{
1099 int ndx =
1101 BuiltinFormatString{ name, {} } )
1103 if (ndx == (int)mNBuiltins)
1104 ndx = mDefaultNdx;
1105
1106 return GetBuiltinFormat(ndx);
1107}
const TranslatableString name
Definition: Distortion.cpp:76
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 1080 of file NumericConverter.cpp.

1081{
1082 if (index >= 0 && index < GetNumBuiltins())
1083 return mBuiltinFormatStrings[index].name;
1084
1085 return {};
1086}

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 1059 of file NumericConverter.cpp.

1060{
1061 // int ndx = 1;
1062 int ndx = std::min(1, GetNumBuiltins() - 1);
1063 int i;
1064
1065 for (i = 0; i < GetNumBuiltins(); i++) {
1066 if (mFormatString == GetBuiltinFormat(i)) {
1067 ndx = i;
1068 break;
1069 }
1070 }
1071
1072 return ndx;
1073}
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 1075 of file NumericConverter.cpp.

1076{
1077 return mNBuiltins;
1078}

References mNBuiltins.

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

Here is the caller graph for this function:

◆ GetString()

wxString NumericConverter::GetString ( )

Definition at line 1109 of file NumericConverter.cpp.

1110{
1112
1113 return mValueString;
1114}

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 580 of file NumericConverter.cpp.

581{ 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{NumericConverter.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 575 of file NumericConverter.cpp.

576{ return TimeConverterFormats_[1].name; }

References BuiltinFormatString::name, and anonymous_namespace{NumericConverter.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 577 of file NumericConverter.cpp.

578{ return TimeConverterFormats_[3].name; }

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

Referenced by ContrastDialog::ContrastDialog().

Here is the caller graph for this function:

◆ Increment()

void NumericConverter::Increment ( )

Definition at line 1116 of file NumericConverter.cpp.

1117{
1118 mFocusedDigit = mDigits.size() - 1;
1119 Adjust(1, 1);
1120}

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 583 of file NumericConverter.cpp.

584{
585 if (id.empty()) {
586 if (type == TIME)
587 return DefaultSelectionFormat();
588 else
589 return ChooseBuiltinFormatStrings(type)[0].name;
590 }
591 else {
594 auto iter = std::find( begin, end, BuiltinFormatString{ id, {} } );
595 if (iter == end)
596 iter = begin;
597 return iter->name;
598 }
599}
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{NumericConverter.cpp}::ChooseBuiltinFormatStrings(), anonymous_namespace{NumericConverter.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 632 of file NumericConverter.cpp.

634{
635 auto format = untranslatedFormat.Translation();
636
637 mPrefix = wxT("");
638 mFields.clear();
639 mDigits.clear();
640 mScalingFactor = 1.0;
641
642 // We will change inFrac to true when we hit our first decimal point.
643 bool inFrac = false;
644 int fracMult = 1;
645 int numWholeFields = 0;
646 int numFracFields = 0;
647 wxString numStr;
648 wxString delimStr;
649 unsigned int i;
650
651 mNtscDrop = false;
652 for(i=0; i<format.length(); i++) {
653 bool handleDelim = false;
654 bool handleNum = false;
655
656 if (format[i] == '|') {
657 wxString remainder = format.Right(format.length() - i - 1);
658 // For languages which use , as a separator.
659 remainder.Replace(wxT(","), wxT("."));
660
661 if (remainder == wxT("#"))
663 else if (remainder == wxT("N")) {
664 mNtscDrop = true;
665 }
666 else
667 // Use the C locale here for string to number.
668 // Translations are often incomplete.
669 // We can't rely on the correct ',' or '.' in the
670 // translation, so we work based on '.' for decimal point.
671 remainder.ToCDouble(&mScalingFactor);
672 i = format.length()-1; // force break out of loop
673 if (!delimStr.empty())
674 handleDelim = true;
675 if (!numStr.empty())
676 handleNum = true;
677 }
678 else if ((format[i] >= '0' && format[i] <='9') ||
679 format[i] == wxT('*') || format[i] == wxT('#')) {
680 numStr += format[i];
681 if (!delimStr.empty())
682 handleDelim = true;
683 }
684 else {
685 delimStr += format[i];
686 if (!numStr.empty())
687 handleNum = true;
688 }
689
690 if (i == format.length() - 1) {
691 if (!numStr.empty())
692 handleNum = true;
693 if (!delimStr.empty())
694 handleDelim = true;
695 }
696
697 if (handleNum) {
698 bool zeropad = false;
699 long range = 0;
700
701 if (numStr.Right(1) == wxT("#"))
702 range = (long int)mSampleRate;
703 else if (numStr.Right(1) != wxT("*")) {
704 numStr.ToLong(&range);
705 }
706 if (numStr.GetChar(0)=='0' && numStr.length()>1)
707 zeropad = true;
708
709 // Hack: always zeropad
710 zeropad = true;
711
712 if (inFrac) {
713 int base = fracMult * range;
714 mFields.push_back(NumericField(inFrac, base, range, zeropad));
715 fracMult *= range;
716 numFracFields++;
717 }
718 else {
719 unsigned int j;
720 for(j=0; j<mFields.size(); j++)
721 mFields[j].base *= range;
722 mFields.push_back(NumericField(inFrac, 1, range, zeropad));
723 numWholeFields++;
724 }
725 numStr = wxT("");
726 }
727
728 if (handleDelim) {
729 bool goToFrac = false;
730
731 if (!inFrac) {
732 wxChar delim = delimStr[delimStr.length()-1];
733 if (delim=='<' || delim=='>') {
734 goToFrac = true;
735 if (delimStr.length() > 1)
736 delimStr = delimStr.BeforeLast(delim);
737 }
738 }
739
740 if (inFrac) {
741 if (numFracFields == 0) {
742 // Should never happen
743 return;
744 }
745 if (handleNum && numFracFields > 1)
746 mFields[mFields.size()-2].label = delimStr;
747 else
748 mFields[mFields.size()-1].label = delimStr;
749 }
750 else {
751 if (numWholeFields == 0)
752 mPrefix = delimStr;
753 else {
754 delimStr.Replace(wxT("<"), wxT(","));
755 delimStr.Replace(wxT(">"), wxT("."));
756 mFields[numWholeFields-1].label = delimStr;
757 }
758 }
759
760 if (goToFrac)
761 inFrac = true;
762 delimStr = wxT("");
763 }
764 }
765
766 for(i = 0; i < mFields.size(); i++) {
767 mFields[i].CreateDigitFormatStr();
768 }
769
770 int pos = 0;
771 int j;
772 mValueMask = wxT("");
773 mValueTemplate = wxT("");
774
776 for(j=0; j<(int)mPrefix.length(); j++)
777 mValueMask += wxT(".");
778 pos += mPrefix.length();
779
780 for(i = 0; i < mFields.size(); i++) {
781 mFields[i].pos = pos;
782
783 for(j=0; j<mFields[i].digits; j++) {
784 mDigits.push_back(DigitInfo(i, j, pos));
785 mValueTemplate += wxT("0");
786 mValueMask += wxT("0");
787 pos++;
788 }
789
790 pos += mFields[i].label.length();
791 mValueTemplate += mFields[i].label;
792 for(j=0; j<(int)mFields[i].label.length(); j++)
793 mValueMask += wxT(".");
794 }
795}
wxT("CloseDown"))
int format
Definition: ExportPCM.cpp:53
TranslatableString label
Definition: TagsEditor.cpp:164
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 797 of file NumericConverter.cpp.

798{
799 unsigned int i;
800
801 wxPrintf("%s", (const char *)mPrefix.mb_str());
802
803 for(i = 0; i < mFields.size(); i++) {
804 if (mFields[i].frac) {
805 wxPrintf("(t * %d) %% %d '%s' ",
806 mFields[i].base,
807 mFields[i].range,
808 (const char *)mFields[i].label.mb_str());
809
810 }
811 else {
812 wxPrintf("(t / %d) %% %d '%s' ",
813 mFields[i].base,
814 mFields[i].range,
815 (const char *)mFields[i].label.mb_str());
816 }
817 }
818
819 wxPrintf("\n");
820}

References label, mFields, and mPrefix.

◆ ResetMaxValue()

void NumericConverter::ResetMaxValue ( )

Definition at line 1048 of file NumericConverter.cpp.

1049{
1050 mMaxValue = std::numeric_limits<double>::max();
1051}

References mMaxValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ ResetMinValue()

void NumericConverter::ResetMinValue ( )

Definition at line 1033 of file NumericConverter.cpp.

1034{
1035 mMinValue = 0.0;
1036}

References mMinValue.

Referenced by NumericConverter().

Here is the caller graph for this function:

◆ SecondsFormat()

NumericFormatSymbol NumericConverter::SecondsFormat ( )
static

Definition at line 573 of file NumericConverter.cpp.

574{ return TimeConverterFormats_[0].name; }

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

Referenced by Grid::Grid().

Here is the caller graph for this function:

◆ SetFormatName()

bool NumericConverter::SetFormatName ( const NumericFormatSymbol formatName)

Definition at line 990 of file NumericConverter.cpp.

991{
992 return
994}
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 996 of file NumericConverter.cpp.

997{
998 if (mFormatString != formatString) {
999 mFormatString = formatString;
1003 return true;
1004 }
1005 else
1006 return false;
1007}
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 1038 of file NumericConverter.cpp.

1039{
1040 mMaxValue = maxValue;
1041 if (mMinValue > maxValue) {
1042 mMinValue = maxValue;
1043 }
1044 if (mValue > maxValue)
1045 SetValue(maxValue);
1046}

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

Here is the call graph for this function:

◆ SetMinValue()

void NumericConverter::SetMinValue ( double  minValue)

Definition at line 1024 of file NumericConverter.cpp.

1025{
1026 mMinValue = minValue;
1027 if (mMaxValue < minValue)
1028 mMaxValue = minValue;
1029 if (mValue < minValue)
1030 SetValue(minValue);
1031}

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

Here is the call graph for this function:

◆ SetSampleRate()

void NumericConverter::SetSampleRate ( double  sampleRate)

Definition at line 1009 of file NumericConverter.cpp.

1010{
1011 mSampleRate = sampleRate;
1015}

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 1017 of file NumericConverter.cpp.

1018{
1019 mValue = newValue;
1022}

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 571 of file NumericConverter.cpp.

572{ return TimeConverterFormats_[6].name; }

References BuiltinFormatString::name, and anonymous_namespace{NumericConverter.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 828 of file NumericConverter.cpp.

829{
831}

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 833 of file NumericConverter.cpp.

834{
835 //rawValue = 4.9995f; Only for testing!
836 if (mType == TIME)
837 rawValue =
838 floor(rawValue * mSampleRate + (nearest ? 0.5f : 0.0f))
839 / mSampleRate; // put on a sample
840 double theValue =
841 rawValue * mScalingFactor
842 // PRL: what WAS this .000001 for? Nobody could explain.
843 // + .000001
844 ;
845 sampleCount t_int;
846 bool round = true;
847 // We round on the last field. If we have a fractional field we round using it.
848 // Otherwise we round to nearest integer.
849 for(unsigned int i = 0; i < mFields.size(); i++) {
850 if (mFields[i].frac)
851 round = false;
852 }
853 if (theValue < 0)
854 t_int = -1;
855 else if(round)
856 t_int = sampleCount(theValue + (nearest ? 0.5f : 0.0f));
857 else
858 {
859 wxASSERT( mFields.back().frac );
860 theValue += (nearest ? 0.5f : 0.0f) / mFields.back().base;
861 t_int = sampleCount(theValue);
862 }
863 double t_frac;
864 if (theValue < 0)
865 t_frac = -1;
866 else
867 t_frac = (theValue - t_int.as_double() );
868 unsigned int i;
869 int tenMins;
870 int mins;
871 int addMins;
872 int secs;
873 int frames;
874
876
877 if(mNtscDrop && theValue >= 0) {
878 frames = (int)(theValue*30./1.001 + (nearest ? 0.5f : 0.0f));
879 tenMins = frames/17982;
880 frames -= tenMins*17982;
881 mins = tenMins * 10;
882 if(frames >= 1800) {
883 frames -= 1800;
884 mins++;
885 addMins = frames/1798;
886 frames -= addMins*1798;
887 mins += addMins;
888 secs = frames/30;
889 frames -= secs*30;
890 frames += 2;
891 if( frames >= 30 ) {
892 secs++;
893 frames -= 30;
894 }
895 }
896 else {
897 secs = frames/30;
898 frames -= secs*30;
899 }
900 t_int = mins * 60 + secs;
901 t_frac = frames / 30.;
902 }
903
904 for(i = 0; i < mFields.size(); i++) {
905 long long value = -1;
906
907 if (mFields[i].frac) {
908 // JKC: This old code looks bogus to me.
909 // The rounding is not propagating to earlier fields in the frac case.
910 //value = (int)(t_frac * mFields[i].base + 0.5); // +0.5 as rounding required
911 // I did the rounding earlier.
912 if (t_frac >= 0)
913 value = t_frac * mFields[i].base;
914 // JKC: TODO: Find out what the range is supposed to do.
915 // It looks bogus too.
916 //if (mFields[i].range > 0)
917 // value = value % mFields[i].range;
918 }
919 else {
920 if (t_int >= 0) {
921 value = t_int.as_long_long() / mFields[i].base;
922 if (mFields[i].range > 0)
923 value = value % mFields[i].range;
924 }
925 }
926
927 wxString field;
928 if (value < 0) {
929 for (int ii = 0; ii < mFields[i].digits; ++ii)
930 field += wxT("-");
931 }
932 else
933 field = wxString::Format(mFields[i].formatStr, (int) value);
935 mValueString += mFields[i].label;
936 }
937}
#define field(n, t)
Definition: ImportAUP.cpp:165
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 188 of file NumericConverter.h.

Referenced by GetBuiltinName().

◆ mDefaultNdx

int NumericConverter::mDefaultNdx
protected

Definition at line 190 of file NumericConverter.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 189 of file NumericConverter.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 164 of file NumericConverter.h.

Referenced by NumericConverter(), and ValueToControls().

◆ mValue

double NumericConverter::mValue
protected

◆ mValueMask

wxString NumericConverter::mValueMask
protected

Definition at line 177 of file NumericConverter.h.

Referenced by ParseFormatString().

◆ mValueString

wxString NumericConverter::mValueString
protected

◆ mValueTemplate

wxString NumericConverter::mValueTemplate
protected

Definition at line 176 of file NumericConverter.h.

Referenced by ParseFormatString().


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