summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin <const@const.me>2023-02-03 19:01:04 +0100
committerKonstantin <const@const.me>2023-02-03 19:01:04 +0100
commit3f3a9a156736d4da0339b3c2d9b042f4ed7c7fb2 (patch)
treec3a4ba4291cb9fd6fae27d1e86c5ec26578aa6a2
parent3ba8e6389679007445f4fc1c52439cb0df3ddba0 (diff)
Refactor, removed a redundant function
-rw-r--r--Examples/WhisperDesktop/CaptureDlg.cpp4
-rw-r--r--Examples/WhisperDesktop/TranscribeDlg.cpp16
-rw-r--r--Examples/WhisperDesktop/Utils/logger.cpp21
-rw-r--r--Examples/WhisperDesktop/Utils/logger.h3
-rw-r--r--Examples/main/textWriter.cpp23
5 files changed, 25 insertions, 42 deletions
diff --git a/Examples/WhisperDesktop/CaptureDlg.cpp b/Examples/WhisperDesktop/CaptureDlg.cpp
index 0bd86f7..95dfe3c 100644
--- a/Examples/WhisperDesktop/CaptureDlg.cpp
+++ b/Examples/WhisperDesktop/CaptureDlg.cpp
@@ -486,9 +486,9 @@ HRESULT CaptureDlg::appendTextFile( Whisper::iTranscribeResult* results, uint32_
if( 0 != ( (uint32_t)threadState.flags & (uint32_t)eTextFlags::Timestamps ) )
{
str = "[";
- printTimeStamp( str, seg.time.begin );
+ printTime( str, seg.time.begin );
str += " --> ";
- printTimeStamp( str, seg.time.end );
+ printTime( str, seg.time.end );
str += "] ";
}
else
diff --git a/Examples/WhisperDesktop/TranscribeDlg.cpp b/Examples/WhisperDesktop/TranscribeDlg.cpp
index 19772e2..d20c0c8 100644
--- a/Examples/WhisperDesktop/TranscribeDlg.cpp
+++ b/Examples/WhisperDesktop/TranscribeDlg.cpp
@@ -455,18 +455,6 @@ namespace
return S_OK;
}
- void printTime( CStringA& rdi, Whisper::sTimeSpan time, bool comma )
- {
- Whisper::sTimeSpanFields fields = time;
- const char separator = comma ? ',' : '.';
- rdi.AppendFormat( "%02d:%02d:%02d%c%03d",
- (int)fields.hours,
- (int)fields.minutes,
- (int)fields.seconds,
- separator,
- fields.ticks / 10'000 );
- }
-
const char* skipBlank( const char* rsi )
{
while( true )
@@ -497,9 +485,9 @@ HRESULT TranscribeDlg::writeTextFile( const sSegment* const segments, const size
if( timestamps )
{
line = "[";
- printTimeStamp( line, seg.time.begin );
+ printTime( line, seg.time.begin );
line += " --> ";
- printTimeStamp( line, seg.time.end );
+ printTime( line, seg.time.end );
line += "] ";
}
else
diff --git a/Examples/WhisperDesktop/Utils/logger.cpp b/Examples/WhisperDesktop/Utils/logger.cpp
index 5c7c257..712835b 100644
--- a/Examples/WhisperDesktop/Utils/logger.cpp
+++ b/Examples/WhisperDesktop/Utils/logger.cpp
@@ -24,14 +24,17 @@ namespace
}
}
-void printTimeStamp( CStringA& rdi, Whisper::sTimeSpan ts )
+void printTime( CStringA& rdi, Whisper::sTimeSpan time, bool comma )
{
- sTimeSpanFields fields = ts;
- uint32_t msec = fields.ticks / 10'000;
- uint32_t hr = fields.days * 24 + fields.hours;
- uint32_t min = fields.minutes;
- uint32_t sec = fields.seconds;
- rdi.AppendFormat( "%02d:%02d:%02d.%03d", hr, min, sec, msec );
+ Whisper::sTimeSpanFields fields = time;
+ const uint32_t hours = fields.days * 24 + fields.hours;
+ const char separator = comma ? ',' : '.';
+ rdi.AppendFormat( "%02d:%02d:%02d%c%03d",
+ (int)hours,
+ (int)fields.minutes,
+ (int)fields.seconds,
+ separator,
+ fields.ticks / 10'000 );
}
HRESULT logNewSegments( const iTranscribeResult* results, size_t newSegments, bool printSpecial )
@@ -50,9 +53,9 @@ HRESULT logNewSegments( const iTranscribeResult* results, size_t newSegments, bo
{
const sSegment& seg = segments[ i ];
str = "[";
- printTimeStamp( str, seg.time.begin );
+ printTime( str, seg.time.begin );
str += " --> ";
- printTimeStamp( str, seg.time.end );
+ printTime( str, seg.time.end );
str += "] ";
for( uint32_t j = 0; j < seg.countTokens; j++ )
diff --git a/Examples/WhisperDesktop/Utils/logger.h b/Examples/WhisperDesktop/Utils/logger.h
index 07ec012..42fefde 100644
--- a/Examples/WhisperDesktop/Utils/logger.h
+++ b/Examples/WhisperDesktop/Utils/logger.h
@@ -33,4 +33,5 @@ HRESULT logNewSegments( const Whisper::iTranscribeResult* results, size_t newSeg
void clearLastError();
bool getLastError( CString& rdi );
-void printTimeStamp( CStringA& rdi, Whisper::sTimeSpan ts ); \ No newline at end of file
+
+void printTime( CStringA& rdi, Whisper::sTimeSpan time, bool comma = false ); \ No newline at end of file
diff --git a/Examples/main/textWriter.cpp b/Examples/main/textWriter.cpp
index 6bb5ac4..6c37c1b 100644
--- a/Examples/main/textWriter.cpp
+++ b/Examples/main/textWriter.cpp
@@ -54,28 +54,19 @@ namespace
return file.Write( bom.data(), 3 );
}
- void printTime( CStringA& rdi, Whisper::sTimeSpan time, bool comma )
+ void printTime( CStringA& rdi, Whisper::sTimeSpan time, bool comma = false )
{
Whisper::sTimeSpanFields fields = time;
+ const uint32_t hours = fields.days * 24 + fields.hours;
const char separator = comma ? ',' : '.';
rdi.AppendFormat( "%02d:%02d:%02d%c%03d",
- (int)fields.hours,
+ (int)hours,
(int)fields.minutes,
(int)fields.seconds,
separator,
fields.ticks / 10'000 );
}
- void printTimeStamp( CStringA& rdi, Whisper::sTimeSpan ts )
- {
- Whisper::sTimeSpanFields fields = ts;
- uint32_t msec = fields.ticks / 10'000;
- uint32_t hr = fields.days * 24 + fields.hours;
- uint32_t min = fields.minutes;
- uint32_t sec = fields.seconds;
- rdi.AppendFormat( "%02d:%02d:%02d.%03d", hr, min, sec, msec );
- }
-
const char* skipBlank( const char* rsi )
{
while( true )
@@ -117,9 +108,9 @@ namespace
if( timestamps )
{
line = "[";
- printTimeStamp( line, seg.time.begin );
+ printTime( line, seg.time.begin );
line += " --> ";
- printTimeStamp( line, seg.time.end );
+ printTime( line, seg.time.end );
line += "] ";
}
else
@@ -178,9 +169,9 @@ namespace
const sSegment& seg = segments[ i ];
line = "";
- printTime( line, seg.time.begin, false );
+ printTime( line, seg.time.begin );
line += " --> ";
- printTime( line, seg.time.end, false );
+ printTime( line, seg.time.end );
line += "\r\n";
line += skipBlank( seg.text );
line += "\r\n\r\n";