Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
1.6.0-bacon0
1.6.0-bacon1
Contributions:
drbscl
Add 64 bit soundfont support (#211)

Fixes:
Add 64 bit soundfont support (#211)
Skip randomly generated project name if a directory with that name already exists (#175)

1.5.0-bacon3
Contributions:
Expand Down
3 changes: 2 additions & 1 deletion docs/wiki/What-is-LittlePiggyTracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ After that you can copy additional wavs to the lgptRoot/lgptProject/samples dire

## New project

When creating a new project, use the regen button to generate a random name. Generate a new name with Regen or edit it manually selecting characters with A and pressing up/down
When creating a new project, use the Random button to generate a random name. Generate a new name with Random or edit it manually selecting characters with A and pressing up/down
Attempting to create a project with the same name in the same location produces a notification that this operation is denied

## Multiple Projects

Expand Down
2 changes: 1 addition & 1 deletion sources/Application/Model/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#define PROJECT_NUMBER "1"
#define PROJECT_RELEASE "6"
#define BUILD_COUNT "0-bacon0"
#define BUILD_COUNT "0-bacon1"

#define MAX_TAP 3

Expand Down
40 changes: 23 additions & 17 deletions sources/Application/Views/ModalDialogs/NewProjectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
#include "NewProjectDialog.h"
#include "Application/Utils/RandomNames.h"

static char *buttonText[BUTTONS_LENGTH] = {
(char *)"Regen",
(char *)"Ok",
(char *)"Cancel"
} ;
static char *buttonText[BUTTONS_LENGTH] = {(char *)"Random", (char *)"Ok",
(char *)"Cancel"};

#define DIALOG_WIDTH 20

NewProjectDialog::NewProjectDialog(View &view):ModalView(view) {}
NewProjectDialog::NewProjectDialog(View &view, Path currentPath)
: ModalView(view), currentPath_(currentPath) {}

NewProjectDialog::~NewProjectDialog() {
}
NewProjectDialog::~NewProjectDialog() {}

void NewProjectDialog::DrawView() {

Expand Down Expand Up @@ -49,10 +46,11 @@ void NewProjectDialog::DrawView() {
props.invert_=(selected_==i+1) ;
DrawString(x,4,text,props) ;
}
};
View::EnableNotification();
}

void NewProjectDialog::OnPlayerUpdate(PlayerEventType ,unsigned int currentTick) {
};
void NewProjectDialog::OnPlayerUpdate(PlayerEventType,
unsigned int currentTick) {};

void NewProjectDialog::OnFocus() {
selected_=currentChar_=0;
Expand All @@ -71,7 +69,7 @@ void NewProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
// A modifier
if (mask & EPBM_A) {
if (mask == EPBM_A) {
std::string randomName = getRandomName();
std::string randomName = "";
switch (selected_) {
case 0:
if (name_[currentChar_] == ' ') {
Expand All @@ -80,14 +78,22 @@ void NewProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
isDirty_ = true;
break;
case 1:
std::fill(name_ + randomName.length(),
name_ + sizeof(name_) / sizeof(name_[0]), ' ');
strncpy(name_, randomName.c_str(), randomName.length());
lastChar_ = currentChar_ = randomName.length() - 1;
do {
randomName = getRandomName();
std::fill(name_ + randomName.length(),
name_ + sizeof(name_) / sizeof(name_[0]), ' ');
strncpy(name_, randomName.c_str(), randomName.length());
lastChar_ = currentChar_ = randomName.length() - 1;
} while (currentPath_.Descend(GetName()).Exists());
isDirty_ = true;
break;
case 2:
EndModal(1);
if (currentPath_.Descend(GetName()).Exists()) {
std::string res("Name " + std::string(name_) + " busy");
View::SetNotification(res.c_str(), -6);
} else {
EndModal(1);
}
break;
case 3:
EndModal(0);
Expand Down
24 changes: 13 additions & 11 deletions sources/Application/Views/ModalDialogs/NewProjectDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@

class NewProjectDialog:public ModalView {
public:
NewProjectDialog(View &view) ;
virtual ~NewProjectDialog() ;
NewProjectDialog(View &view, Path currentPath = "");
virtual ~NewProjectDialog();

virtual void DrawView() ;
virtual void OnPlayerUpdate(PlayerEventType ,unsigned int currentTick) ;
virtual void OnFocus() ;
virtual void ProcessButtonMask(unsigned short mask,bool pressed) ;
virtual void DrawView();
virtual void OnPlayerUpdate(PlayerEventType, unsigned int currentTick);
virtual void OnFocus();
virtual void ProcessButtonMask(unsigned short mask, bool pressed);

std::string GetName();

std::string GetName() ;
private:
int selected_ ;
int lastChar_ ;
char name_[MAX_NAME_LENGTH+1] ;
int currentChar_ ;
Path currentPath_;
int selected_;
int lastChar_;
char name_[MAX_NAME_LENGTH + 1];
int currentChar_;
} ;

#endif
128 changes: 64 additions & 64 deletions sources/Application/Views/ModalDialogs/SelectProjectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
#define LIST_SIZE 20
#define LIST_WIDTH 32

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

Path SelectProjectDialog::lastFolder_("root:") ;
int SelectProjectDialog::lastProject_ = 0 ;
Expand All @@ -25,12 +21,11 @@ static void NewProjectCallback(View &v,ModalView &dialog) {
std::string selected=npd.GetName() ;
SelectProjectDialog &spd=(SelectProjectDialog&)v ;
Result result = spd.OnNewProject(selected) ;
if (result.Failed())
{
Trace::Error(result.GetDescription().c_str());
if (result.Failed()) {
Trace::Error(result.GetDescription().c_str());
}
}
}
} ;
};

SelectProjectDialog::SelectProjectDialog(View &view):ModalView(view),content_(true) {
}
Expand All @@ -45,16 +40,17 @@ void SelectProjectDialog::DrawView() {
GUITextProperties props ;

SetColor(CD_NORMAL) ;
View::EnableNotification();

// Draw projects
// Draw projects

int x=1 ;
int y=1 ;
int x = 1;
int y = 1;

if (currentProject_<topIndex_) {
topIndex_=currentProject_ ;
} ;
if (currentProject_>=topIndex_+LIST_SIZE) {
if (currentProject_ < topIndex_) {
topIndex_ = currentProject_;
};
if (currentProject_>=topIndex_+LIST_SIZE) {
topIndex_=currentProject_-LIST_SIZE+1 ;
} ;

Expand Down Expand Up @@ -113,12 +109,11 @@ void SelectProjectDialog::DrawView() {
x=offset*(i+1)-strlen(text)/2 ;
props.invert_=(i==selected_)?true:false ;
DrawString(x,y,text,props) ;
}

}
};

void SelectProjectDialog::OnPlayerUpdate(PlayerEventType ,unsigned int currentTick) {
};
void SelectProjectDialog::OnPlayerUpdate(PlayerEventType,
unsigned int currentTick) {};

void SelectProjectDialog::OnFocus() {

Expand All @@ -129,29 +124,30 @@ void SelectProjectDialog::OnFocus() {

void SelectProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
if (!pressed) return ;

if (mask&EPBM_B) {
if (mask&EPBM_UP) warpToNextProject(-LIST_SIZE) ;
if (mask&EPBM_DOWN) warpToNextProject(LIST_SIZE) ;
} else {

// A modifier
if (mask&EPBM_A) {
switch(selected_) {

if (mask&EPBM_B) {
if (mask & EPBM_UP)
warpToNextProject(-LIST_SIZE);
if (mask&EPBM_DOWN) warpToNextProject(LIST_SIZE) ;
} else {

// A modifier
if (mask & EPBM_A) {
switch (selected_) {
case 0: // load
{
//locate folder user had selected when they hit a
int count=0 ;
Path *current=0 ;

IteratorPtr<Path> it(content_.GetIterator()) ;
for(it->Begin();!it->IsDone();it->Next()) {
if (count==currentProject_) {
current=&it->CurrentItem() ;
break ;
}
count++ ;
}
// locate folder user had selected when they hit a
int count = 0;
Path *current = 0;

IteratorPtr<Path> it(content_.GetIterator());
for (it->Begin(); !it->IsDone(); it->Next()) {
if (count == currentProject_) {
current = &it->CurrentItem();
break;
}
count++;
}

//check if folder is a project, indicated by 'lgpt' being the first 4 characters of the folder name
std::string name = current->GetName() ;
Expand All @@ -178,20 +174,21 @@ void SelectProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
}
case 1: // new
{
NewProjectDialog *npd=new NewProjectDialog(*this) ;
DoModal(npd,NewProjectCallback) ;
NewProjectDialog *npd =
new NewProjectDialog(*this, currentPath_);
DoModal(npd,NewProjectCallback) ;
break ;
}
case 2: // Exit ;
EndModal(0) ;
}
case 2: // Exit ;
EndModal(0) ;
break ;
}
} else {
} else {

// R Modifier
// R Modifier

if (mask&EPBM_R) {
} else {
if (mask & EPBM_R) {
} else {
// No modifier
if (mask==EPBM_UP) warpToNextProject(-1) ;
if (mask==EPBM_DOWN) warpToNextProject(1) ;
Expand All @@ -204,16 +201,16 @@ void SelectProjectDialog::ProcessButtonMask(unsigned short mask,bool pressed) {
selected_=(selected_+1)%3 ;
isDirty_=true ;
}
}
}
}
}
}
}
};

void SelectProjectDialog::warpToNextProject(int amount) {

int offset=currentProject_-topIndex_ ;
int size=content_.Size() ;
currentProject_+=amount ;
int offset = currentProject_ - topIndex_;
int size = content_.Size();
currentProject_+=amount ;
if (currentProject_<0) currentProject_+=size ;
if (currentProject_>=size) currentProject_-=size ;

Expand All @@ -223,8 +220,7 @@ void SelectProjectDialog::warpToNextProject(int amount) {
topIndex_=0 ;
} ;
}
isDirty_=true ;

isDirty_ = true;
}

Path SelectProjectDialog::GetSelection() {
Expand All @@ -233,8 +229,14 @@ Path SelectProjectDialog::GetSelection() {

Result SelectProjectDialog::OnNewProject(std::string &name) {

Path path = currentPath_.Descend(name);
Trace::Log("TMP","creating project at %s",path.GetPath().c_str());
Path path = currentPath_.Descend(name);
if (path.Exists()) {
Trace::Log("SelectProjectDialog:OnNewProj","path already exists %s", path.GetPath().c_str());
std::string res("Name " + name + " busy");
View::SetNotification(res.c_str(), 0);
return Result(res);
}
Trace::Log("TMP","creating project at %s",path.GetPath().c_str());
selection_ = path ;
Result result = FileSystem::GetInstance()->MakeDir(path.GetPath().c_str()) ;
RETURN_IF_FAILED(result, ("Failed to create project dir for '%s", path.GetPath().c_str()));
Expand Down Expand Up @@ -289,7 +291,5 @@ void SelectProjectDialog::setCurrentFolder(Path &path) {
//reset & redraw screen
topIndex_=0 ;
currentProject_=0 ;
isDirty_=true ;
isDirty_ = true;
}