Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sources/Application/Persistency/PersistencyService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,22 @@ bool PersistencyService::Load() {
}
return true ;
} ;

// Delete all samples and project files, free up memory
bool PersistencyService::Delete() {

Path filename("project:lgptsav.dat");
PersistencyDocument doc(filename.GetPath());

// Try opening the file

FileSystem *fs = FileSystem::GetInstance();
I_File *file = fs->Open(filename.GetPath().c_str(), "r");
if (!file)
return false;

// delete file ;
// PurgeAllInstruments()

return false;
};
1 change: 1 addition & 0 deletions sources/Application/Persistency/PersistencyService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PersistencyService: public Service,public T_Singleton<PersistencyService>
PersistencyService() ;
void Save() ;
bool Load() ;
bool Delete();
} ;

class PersistencyDocument: public TiXmlDocument {
Expand Down
59 changes: 33 additions & 26 deletions sources/Application/Views/ModalDialogs/SelectProjectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
#define LIST_SIZE 20
#define LIST_WIDTH 32

static char *buttonText[3]= {
"Load",
"New",
"Exit"
} ;
#define NUM_BUTTONS 4

static char *buttonText[NUM_BUTTONS] = {"Load", "New", "Delete", "Exit"};

Path SelectProjectDialog::lastFolder_("root:") ;
int SelectProjectDialog::lastProject_ = 0 ;
Expand Down Expand Up @@ -103,18 +101,17 @@ void SelectProjectDialog::DrawView() {
count++ ;
} ;

y=LIST_SIZE+2 ;
int offset=LIST_WIDTH/4 ;
y = LIST_SIZE + 2;
int offset=LIST_WIDTH/(NUM_BUTTONS + 1);

SetColor(CD_NORMAL) ;

for (int i=0;i<3;i++) {
const char *text=buttonText[i] ;
for (int i = 0; i < NUM_BUTTONS; i++) {
const char *text=buttonText[i] ;
x=offset*(i+1)-strlen(text)/2 ;
props.invert_=(i==selected_)?true:false ;
DrawString(x,y,text,props) ;
}

props.invert_ = (i == selected_) ? true : false;
DrawString(x, y, text, props);
}
};

void SelectProjectDialog::OnPlayerUpdate(PlayerEventType ,unsigned int currentTick) {
Expand Down Expand Up @@ -181,8 +178,18 @@ void SelectProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
NewProjectDialog *npd=new NewProjectDialog(*this) ;
DoModal(npd,NewProjectCallback) ;
break ;
}
case 2: // delete
{
// Is it a project directory?
// if so, ask form confirmation
// tell fs to remove it all
// show success (or failure)
// if not a project dir, show msg
// show SelectProectDialog once more
break ;
}
case 2: // Exit ;
case 3: // Exit ;
EndModal(0) ;
break ;
}
Expand All @@ -195,18 +202,18 @@ void SelectProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
// No modifier
if (mask==EPBM_UP) warpToNextProject(-1) ;
if (mask==EPBM_DOWN) warpToNextProject(1) ;
if (mask==EPBM_LEFT) {
selected_-- ;
if (selected_<0) selected_+=3 ;
isDirty_=true ;
}
if (mask==EPBM_RIGHT) {
selected_=(selected_+1)%3 ;
isDirty_=true ;
}
}
}
}
if (mask == EPBM_LEFT) {
selected_--;
if (selected_ < 0) selected_ += NUM_BUTTONS;
isDirty_ = true;
}
if (mask == EPBM_RIGHT) {
selected_ = (selected_ + 1) % NUM_BUTTONS;
isDirty_ = true;
}
}
}
}
};

void SelectProjectDialog::warpToNextProject(int amount) {
Expand Down
52 changes: 44 additions & 8 deletions sources/Application/Views/ProjectView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define ACTION_QUIT MAKE_FOURCC('Q','U','I','T')
#define ACTION_PURGE_INSTRUMENT MAKE_FOURCC('P','R','G','I')
#define ACTION_TEMPO_CHANGED MAKE_FOURCC('T','E','M','P')
#define ACTION_DELETE MAKE_FOURCC('D', 'E', 'S', 'O')

static void SaveAsProjectCallback(View &v,ModalView &dialog) {

Expand Down Expand Up @@ -92,6 +93,12 @@ static void PurgeCallback(View &v,ModalView &dialog) {
((ProjectView &)v).OnPurgeInstruments(dialog.GetReturnCode()==MBL_YES) ;
} ;

static void DeleteProjectCallback(View &v, ModalView &dialog) {
if (dialog.GetReturnCode() == MBL_YES) {
((ProjectView &)v).OnDelete();
}
};

ProjectView::ProjectView(GUIWindow &w,ViewData *data):FieldView(w,data) {

lastClock_=0 ;
Expand Down Expand Up @@ -166,6 +173,11 @@ ProjectView::ProjectView(GUIWindow &w,ViewData *data):FieldView(w,data) {
a1->AddObserver(*this);
T_SimpleList<UIField>::Insert(a1);

position._y += 2;
a1 = new UIActionField("Delete Song", ACTION_DELETE, position);
a1->AddObserver(*this);
T_SimpleList<UIField>::Insert(a1);

v = project_->FindVariable(VAR_MIDIDEVICE);
NAssert(v);
position._y += 2;
Expand All @@ -177,7 +189,6 @@ ProjectView::ProjectView(GUIWindow &w,ViewData *data):FieldView(w,data) {
a1 = new UIActionField("Exit", ACTION_QUIT, position);
a1->AddObserver(*this);
T_SimpleList<UIField>::Insert(a1);

}

ProjectView::~ProjectView() {
Expand Down Expand Up @@ -249,13 +260,15 @@ void ProjectView::Update(Observable &,I_ObservableData *data) {
case ACTION_PURGE:
project_->Purge() ;
break ;
case ACTION_PURGE_INSTRUMENT:

case ACTION_PURGE_INSTRUMENT:
{
MessageBox *mb=new MessageBox(*this,"Purge unused samples from disk ?",MBBF_YES|MBBF_NO) ;
DoModal(mb,PurgeCallback) ;
break ;
}
case ACTION_SAVE:

case ACTION_SAVE:
if (!player->IsRunning()) {
PersistencyService *service=PersistencyService::GetInstance() ;
service->Save() ;
Expand All @@ -264,14 +277,14 @@ void ProjectView::Update(Observable &,I_ObservableData *data) {
DoModal(mb) ;
}
break ;
case ACTION_SAVE_AS:

case ACTION_SAVE_AS:
if (!player->IsRunning()) {
PersistencyService *service=PersistencyService::GetInstance() ;
service->Save() ;
NewProjectDialog *mb=new NewProjectDialog(*this) ;
DoModal(mb,SaveAsProjectCallback) ;

} else {
DoModal(mb, SaveAsProjectCallback);
} else {
MessageBox *mb=new MessageBox(*this,"Not while playing",MBBF_OK) ;
DoModal(mb) ;
}
Expand All @@ -288,6 +301,22 @@ void ProjectView::Update(Observable &,I_ObservableData *data) {
}
break ;
}

case ACTION_DELETE:
{
if (player->IsRunning()) {
// Ideally just stop it now
MessageBox *mb =
new MessageBox(*this, "Not while playing", MBBF_OK);
DoModal(mb);
} else {
MessageBox *mb = new MessageBox(*this, "Delete this song forever?",
MBBF_YES | MBBF_NO);
DoModal(mb, DeleteProjectCallback);
}
break;
}

case ACTION_QUIT:
{
if (!player->IsRunning()) {
Expand All @@ -299,7 +328,8 @@ void ProjectView::Update(Observable &,I_ObservableData *data) {
}
break ;
}
case ACTION_TEMPO_CHANGED:

case ACTION_TEMPO_CHANGED:
break ;
default:
NInvalid ;
Expand All @@ -325,6 +355,12 @@ void ProjectView::OnSaveAsProject(char * data) {
NotifyObservers(&ve) ;
} ;

void ProjectView::OnDelete() {
SetChanged();
// TODO delete actually
// Send ViewEvent
}

void ProjectView::OnQuit() {
ViewEvent ve(VET_QUIT_APP) ;
SetChanged();
Expand Down
3 changes: 2 additions & 1 deletion sources/Application/Views/ProjectView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ProjectView: public FieldView,public I_Observer {

void Update(Observable &,I_ObservableData *) ;

void OnLoadProject() ;
void OnDelete();
void OnLoadProject() ;
void OnSaveAsProject(char * data) ;
void OnPurgeInstruments(bool removeFromDisk) ;
void OnQuit() ;
Expand Down