Exemple #1
0
        public void Start()
        {
            while (true)
            {
                Console.Clear();

                string topLine =
                    $@"
Name: {currentName} | 
Cursor: ({cursorPos.x}/{cursorPos.y}) | 
Instrument: {InstrumentUtil.GetInstrumentName((Instrument)selectedInstrument)} | 
Current Layer: {selectedLayer} | 
BPM: {currentBPM} | 
Scroll: {pageStart}
                    ".Replace(Environment.NewLine, "");
                Console.WriteLine(topLine);
                SelectedLayer.PrintNoteGrid(cursorPos);

                var key = Console.ReadKey(true);

                if (commands.ContainsKey(key.Key))
                {
                    commands[key.Key].RunCommand(key);
                }
            }
        }
        protected override bool OnCommand(ConsoleKeyInfo pressed)
        {
            Console.Write("Instrument [c (change)/Esc (Exit)]: ");
            var sub = Console.ReadKey(false);

            Console.WriteLine();
            switch (sub.Key)
            {
            case ConsoleKey.C:
                Console.Clear();
                Console.WriteLine("Enter new instrument name:");
                foreach (string s in InstrumentUtil.GetInstrumentNames().Skip(1))
                {
                    Console.Write($"{textInfo.ToTitleCase(s.ToLower())}, ");
                    Console.WriteLine();
                }

                string newInstrument = Console.ReadLine().ToUpper();
                // if newInstrument is not actually a valid instrument
                if (!InstrumentUtil.instrumentNames.Reverse.ContainsKey(newInstrument))
                {
                    return(false);
                }
                client.selectedInstrument = (int)InstrumentUtil.instrumentNames.Reverse[newInstrument];
                break;

            case ConsoleKey.Escape:
                break;
            }

            return(true);
        }
        protected override bool OnCommand(ConsoleKeyInfo pressed)
        {
            Console.Write("Enter file path to write to: ");

            StringBuilder encoded = new StringBuilder();

            encoded.Append($"{client.currentName}/").Append($"{client.currentBPM}/");

            for (int x = 0; x < Layer.WIDTH; x++)
            {
                for (int y = 0; y < Layer.HEIGHT; y++)
                {
                    foreach (Layer layer in client.layers.Values)
                    {
                        (string tone, int currOct) = HeightToNoteOctave(y);
                        int currVal = layer.grid.GetValue(new Vec2(x, y));
                        if (currVal != 0)
                        {
                            encoded.Append($"{InstrumentUtil.GetInstrumentName((Instrument)currVal)},{tone},{currOct};");
                        }
                    }
                }
                encoded.Length -= 1;
                encoded.Append("/");
            }
            encoded.Length -= 1;

            SaveFileDialog saveDialog = new SaveFileDialog
            {
                Filter = "*Melody File (*.melody)|*.melody",
                Title  = "Save your Melody Project File"
            };

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                string savePath = Path.GetFullPath(saveDialog.FileName);
                saveDialog.Dispose();

                if (!savePath.EndsWith("melody"))
                {
                    savePath += ".melody";
                }

                File.WriteAllText(savePath, encoded.ToString());
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
 public string[] ToRowStrings(Vec2 cursorPos, int pageStart)
 {
     string[] output = new string[HEIGHT];
     for (int x = pageStart; x < pageStart + SHOW_AMT; x++)
     {
         for (int y = 0; y < HEIGHT; y++)
         {
             if (cursorPos.x == x && cursorPos.y == y)
             {
                 output[y] += "&11+ ";
             }
             else if (grid[x, y] == (int)Instrument.Pause)
             {
                 output[y] += "- ";
             }
             else
             {
                 output[y] += InstrumentUtil.GetColorCode((Instrument)grid[x, y]) + "# ";
             }
         }
     }
     return(output);
 }