Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Fixed addTracks().
Browse files Browse the repository at this point in the history
  • Loading branch information
Flone-dnb committed Nov 2, 2019
1 parent 9a844ae commit eac75fc
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/Model/AudioService/audioservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ AudioService::AudioService(MainWindow* pMainWindow)

this->pMainWindow = pMainWindow;
pSystem = nullptr;
pRndGen = new std::mt19937_64( static_cast<unsigned long long>(time(nullptr)) );
pRndGen = new std::mt19937_64( std::random_device{}() );
iCurrentlyDrawingTrackIndex = new size_t(0);

bMonitorTracks = false;
Expand Down Expand Up @@ -172,22 +172,8 @@ void AudioService::addTrack(const wchar_t *pFilePath)


// Get track name
size_t iNameStartIndex = 0;
for (size_t i = wPathStr.size() - 1; i >= 1; i--)
{
if (wPathStr[i] == L'/' || wPathStr[i] == L'\\')
{
iNameStartIndex = i + 1;
break;
}
}

std::wstring trackName = L"";
for (size_t i = iNameStartIndex; i < wPathStr.size() - 4; i++)
{
trackName += wPathStr[i];
}
if (trackName.back() == L'.') trackName.pop_back();
std::wstring trackName = getTrackName(pFilePath);



Expand Down Expand Up @@ -268,6 +254,31 @@ void AudioService::addTrack(const wchar_t *pFilePath)
mtxThreadLoadAddTrack.unlock();
}

std::wstring AudioService::getTrackName(const wchar_t *pFilePath)
{
std::wstring wPathStr(pFilePath);

size_t iNameStartIndex = 0;
for (size_t i = wPathStr.size() - 1; i >= 1; i--)
{
if (wPathStr[i] == L'/' || wPathStr[i] == L'\\')
{
iNameStartIndex = i + 1;
break;
}
}

std::wstring trackName = L"";
for (size_t i = iNameStartIndex; i < wPathStr.size() - 4; i++)
{
trackName += wPathStr[i];
}
if (trackName.back() == L'.') trackName.pop_back();


return trackName;
}

void AudioService::addTracks(std::vector<wchar_t*> paths)
{
// This function adds tracks by using private 'threadAddTracks()' and 'addTrack()' functions.
Expand Down Expand Up @@ -353,11 +364,10 @@ void AudioService::addTracks(std::vector<wchar_t*> paths)
delete allCount;
pMainWindow->hideWaitWindow();

// Wait a little for all track widgets to show
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (tracks.size() > 0) pMainWindow->setFocusOnTrack(tracks.size() - 1);

mtxTracksVec.unlock();

pMainWindow->showAllTracks();

return;
}

Expand Down
14 changes: 14 additions & 0 deletions src/View/SearchWindow/searchwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "searchwindow.h"
#include "ui_searchwindow.h"

SearchWindow::SearchWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SearchWindow)
{
ui->setupUi(this);
}

SearchWindow::~SearchWindow()
{
delete ui;
}
22 changes: 22 additions & 0 deletions src/View/SearchWindow/searchwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef SEARCHWINDOW_H
#define SEARCHWINDOW_H

#include <QMainWindow>

namespace Ui {
class SearchWindow;
}

class SearchWindow : public QMainWindow
{
Q_OBJECT

public:
explicit SearchWindow(QWidget *parent = nullptr);
~SearchWindow();

private:
Ui::SearchWindow *ui;
};

#endif // SEARCHWINDOW_H
24 changes: 24 additions & 0 deletions src/View/SearchWindow/searchwindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>SearchWindow</class>
<widget name="SearchWindow" class="QMainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget name="menubar" class="QMenuBar"/>
<widget name="centralwidget" class="QWidget"/>
<widget name="statusbar" class="QStatusBar"/>
</widget>
<pixmapfunction/>
<connections/>
</ui>

0 comments on commit eac75fc

Please sign in to comment.