Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
rohan-av authored Oct 24, 2019
2 parents 9028f5b + 06d2e06 commit c7e8483
Showing 6 changed files with 99 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -2,14 +2,18 @@

import duke.commands.AddBarCommand;
import duke.commands.AddOverlayCommand;
import duke.commands.AsciiCommand;
import duke.commands.Command;
import duke.commands.CopyCommand;
import duke.commands.ViewCommand;
import duke.commands.GroupCommand;
import duke.commands.HelpCommand;
import duke.commands.ListCommand;
import duke.commands.NewCommand;
import duke.commands.RemindCommand;
import duke.commands.ViewCommand;



import duke.components.SongList;

import java.nio.file.Paths;
@@ -81,7 +85,8 @@ public void run() {
|| c instanceof GroupCommand
|| c instanceof CopyCommand
|| c instanceof AddOverlayCommand
|| c instanceof ListCommand) {
|| c instanceof ListCommand
|| c instanceof AsciiCommand) {
output = c.execute(songs, ui, storage);
} else {
output = c.execute(tasks, ui, storage);
4 changes: 4 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -139,6 +139,10 @@ public String getMessage() {
message = "OOPS!!! The data is corrupted.";
break;
}
case "AsciiCommand": {
message = "OOPS!!! Your Ascii Command is not recognised.";
break;
}
default: {
message = "OOPS!!! I'm sorry, but I don't know what that means :-(";
}
86 changes: 84 additions & 2 deletions src/main/java/duke/commands/AsciiCommand.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,98 @@
package duke.commands;

import duke.DukeException;
import duke.Storage;
import duke.Ui;
import duke.components.Bar;
import duke.components.Chord;
import duke.components.Group;
import duke.components.Note;
import duke.components.Pitch;
import duke.components.Song;
import duke.components.SongList;
import duke.components.VerseList;

import java.util.ArrayList;

public class AsciiCommand {
public class AsciiCommand extends Command<SongList> {

//@@author Samuel787

private String message;
private Song song;

/**
* Constructor for the command to print out a bar, group or song in ASCII.
* @param message the input message that resulted in the creation of the duke.Commands.Command
*/
public AsciiCommand(String message) {
this.message = message.trim();
}

/**
* Prints out a bar, group or song in ASCII to represent the song sheet for that component.
* @param songList the duke.TaskList or duke.components.SongList object that contains the task list in use
* @param ui the Ui object responsible for the reading of user input and the display of
* the responses
* @param storage the Storage object used to read and manipulate the .txt file
* @return the string corresponding to the ASCII song sheet as requested by user
* @throws DukeException if an exception occurs in the parsing of the message or in IO
*/
@Override
public String execute(SongList songList, Ui ui, Storage storage) throws DukeException {
String result = "";
if (message.length() < 6 || !message.substring(0, 6).equals("ascii ")) {
throw new DukeException(message);
}
try {
message = message.substring(6).trim();
String command = message.split(" ")[0];
if (command.equals("bar")) {
int barNum = Integer.parseInt(message.split(" ")[1]);
//get the current song out
Song song = new Song("Test song", "C-Major", 120);
//bar index for user is assumed to start from 1
if (barNum > song.getNumBars() || barNum < 1) {
throw new DukeException(message, "AsciiCommand");
}
Bar bar = song.getBars().get(barNum - 1);
result = printBarAscii(bar);
} else if (command.equals("group")) {
String groupName = message.split(" ")[1];
//Get the verseList from storage
VerseList verseList = new VerseList();
Group group = verseList.find(groupName);
if (group == null) {
throw new DukeException(message, "AsciiCommand");
} else {
result = printGroupAscii(group);
}
} else if (command.equals("song")) {
String songName = message.split(" ")[1];
//Get the song from the storage
Song song = new Song("Test song", "C-Major", 120);
//if song exists
result = printSongAscii(song);
} else {
//wrong command
throw new DukeException(message, "AsciiCommand");
}
} catch (NumberFormatException | IndexOutOfBoundsException e) {
throw new DukeException(message, "AsciiCommand");
}
return result;
}

/**
* Returns a boolean value representing whether the program will terminate or not, used in
* duke.Duke to reassign a boolean variable checked at each iteration of a while loop.
*
* @return a boolean value that represents whether the program will terminate after the command
*/
@Override
public boolean isExit() {
return false;
}

private static final String MUSIC_8 = "*";
private static final String MUSIC_6 = "$.";
@@ -25,7 +108,6 @@ public class AsciiCommand {
private static final String REST_1 = "&";
private static final String CONT = "-";

//@@author Samuel787
/**
* Prints out the selected bar in ASCII format to represnt the song sheet.
* @param bar the bar that user wants to print in ASCII
1 change: 1 addition & 0 deletions src/main/java/duke/commands/CopyCommand.java
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
*/
public class CopyCommand extends Command<SongList> {

//@@author Samuel787
private String message;
private Song song; //current working song

3 changes: 2 additions & 1 deletion src/main/java/duke/commands/GroupCommand.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
*/
public class GroupCommand extends Command<SongList> {

//@@author Samuel787
private String message;
private Song song;

@@ -58,7 +59,7 @@ public String execute(SongList songList, Ui ui, Storage storage) throws DukeExce
//code to add this group into the storage (verse list)

return ui.formatGroupBar(startNo, endNo, name);
} catch (Exception e) {
} catch (NumberFormatException | IndexOutOfBoundsException e) {
throw new DukeException(message, "group");
}
}
1 change: 1 addition & 0 deletions src/main/java/duke/components/VerseList.java
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

public class VerseList {

//@@author Samuel787
private ArrayList<Group> verseList = new ArrayList<>();

/**

0 comments on commit c7e8483

Please sign in to comment.