Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        try
        {
            xmlReader = this.GetComponent <XMLReaderMusic>();
            if (FileName != null)
            {
                xmlReader.ReadLocalFile(FileName);
                musicSheet = xmlReader.musicSheet;
            }
        }
        catch { }

        initPositionNotes = musicSheet.InitPositionNotes;
        Tempo             = musicSheet.Tempo;
        TotalMeasures     = musicSheet.TotalMeasures;
        BeatsPerMeasure   = musicSheet.BeatsPerMeasure;
        actualBeat        = 1;
        actualMeasure     = 1;
        tempoSong         = 60f / Tempo;
        sw          = new Stopwatch();
        this.speed  = -0.0945f * (Tempo / 60f);
        actualScore = 0;
        partBeat    = 1;
        sw.Start();
        UpdateTimmer();
    }
Esempio n. 2
0
    private void LoadLevel(string name)
    {
        uiMenu.SetActive(false);
        uiHud.SetActive(false);

        playerGameObject = Instantiate(playerPrefab);

        noteSpawnPositions = new Dictionary <string, float>();

        try
        {
            MusicSheet sheet = LevelLoader.Load(name);
            for (int i = 0; i < sheet.keys.Length; ++i)
            {
                Key key            = sheet.keys[i];
                var y              = keyStartHeight - (keyDistanceApart * i);
                var noteGameObject = Instantiate(noteTriggerPrefab, new Vector3(0, y), Quaternion.identity);
                noteGameObject.GetComponent <NoteTriggerController>().clip = Resources.Load <AudioClip>(Path.Combine("Audio", key.file));
                noteGameObject.GetComponent <NoteTriggerController>().note = key.note;

                noteSpawnPositions.Add(key.note, y);
            }
            loadedLevel = sheet;
        } catch (Exception e)
        {
            Console.WriteLine(e);
            CleanUpLevel();
            state = GameState.MainMenu;
        }
    }
Esempio n. 3
0
 // Update is called once per frame
 void Update()
 {
     if (!_Activated && _Player.Collider.bounds.Intersects(_Collider.bounds))
     {
         _Activated = true;
         MusicSheet.Enable();
     }
 }
Esempio n. 4
0
 private void Awake()
 {
     TotalMeasures   = 0;
     actual_measure  = 1;
     actual_beat     = 1;
     actual_partbeat = 1;
     this.Notes      = new List <NoteMusicSheet>();
     this.musicSheet = new MusicSheet();
 }
Esempio n. 5
0
        public RawMusicSheet Serialize(MusicSheet musicSheet)
        {
            var name      = musicSheet.Title;
            var tempo     = SerializeTempo(musicSheet);
            var meter     = SerializeMeter(musicSheet);
            var melody    = SerializeMelody(musicSheet);
            var algorithm = SerializeAlgorithm();

            return(new RawMusicSheet(name, tempo, meter, melody, algorithm));
        }
        private string SerializeMelody(MusicSheet musicSheet)
        {
            var stringBuilder = new StringBuilder();

            foreach (var chordOffset in musicSheet.Melody)
            {
                stringBuilder.Append(" ");
                stringBuilder.Append(_chordOffsetSerializer.Serialize(chordOffset));
            }

            return(stringBuilder.ToString());
        }
        public void handle(MidiContext context, MidiEvent midiEvent)
        {
            this.context    = context;
            this.musicSheet = context.MusicSheet;

            var channelMessage = midiEvent.MidiMessage as ChannelMessage;

            if (channelMessage.Command.ToString().Equals("NoteOn"))
            {
                ProcessNote(midiEvent);
            }
        }
        public RawMusicSheet Serialize(MusicSheet musicSheet)
        {
            var artist     = musicSheet.Artist;
            var title      = musicSheet.Title;
            var user       = musicSheet.User;
            var instrument = musicSheet.Instrument;
            var tempo      = SerializeTempo(musicSheet);
            var meter      = SerializeMeter(musicSheet);
            var melody     = SerializeMelody(musicSheet);
            var algorithm  = SerializeAlgorithm();

            return(new RawMusicSheet(artist, title, user, instrument, tempo, meter, melody, algorithm));
        }
        public MusicSheet ReadFile(string path)
        {
            var musicSheet = new MusicSheet();

            StringBuilder builder = new StringBuilder();

            foreach (var line in File.ReadAllLines(path))
            {
                builder.AppendLine(line);
            }

            musicSheet.SymbolsContent = builder;

            return(musicSheet);
        }
Esempio n. 10
0
        public ActionResult NoteAction(int?id)
        {
            ViewBag.drpCourseLevel = CommonController.drpCourseLevel();
            ViewBag.drpInstrument  = CommonController.drpInstrument();
            ViewBag.drpMusic       = CommonController.drpMusic();

            if (id != 0)
            {
                MusicSheet dataset = entities.MusicSheets.Find(id);
                return(PartialView(dataset));
            }

            else
            {
                return(PartialView());
            }
        }
Esempio n. 11
0
    // CLASS FUNCTIONS
    void generatePianoUI()
    {
        int        whiteKeyIndex = 0;
        int        blackKeyIndex = 0;
        Vector2    prevPos       = Vector2.zero;
        GameObject tmp           = Instantiate(whiteKeyPrefab);
        float      whiteKeyWidth = tmp.GetComponent <RectTransform>().rect.width;

        Destroy(tmp);
        for (int i = 21; i <= 108; ++i)
        {
            if (!MusicSheet.getNoteNameByNumber(i).Contains("#"))
            {
                PianoKey key = Instantiate(whiteKeyPrefab, transform).GetComponent <PianoKey>();
                key.number = i;
                key.GetComponent <RectTransform>().localPosition = new Vector2(key.GetComponent <RectTransform>().rect.width *whiteKeyIndex - 960, 0);
                keyDict[i] = key;
                whiteKeyIndex++;
            }
            else
            {
                PianoKey key = Instantiate(blackKeyPrefab, transform).GetComponent <PianoKey>();
                key.number = i;
                if (i == 22)
                {
                    key.GetComponent <RectTransform>().localPosition = new Vector2(whiteKeyWidth - key.GetComponent <RectTransform>().rect.width * 0.5f - 960, 0);
                }
                else
                {
                    if (blackKeyIndex % 5 == 1 || blackKeyIndex % 5 == 3)
                    {
                        key.GetComponent <RectTransform>().localPosition = new Vector2(prevPos.x + 2 * whiteKeyWidth, 0);
                    }
                    else if (blackKeyIndex % 5 == 0 || blackKeyIndex % 5 == 2 || blackKeyIndex % 5 == 4)
                    {
                        key.GetComponent <RectTransform>().localPosition = new Vector2(prevPos.x + whiteKeyWidth, 0);
                    }
                }
                prevPos    = key.GetComponent <RectTransform>().localPosition;
                keyDict[i] = key;
                blackKeyIndex++;
            }
        }
    }
Esempio n. 12
0
        public ActionResult NoteAction(MusicSheet music)
        {
            ModelState.Remove("MusicSheetID");

            if (ModelState.IsValid)
            {
                string msg = "";

                if (music.MusicSheetID > 0)
                {
                    var dataset = entities.MusicSheets.Where(f => f.MusicSheetID == music.MusicSheetID).FirstOrDefault();
                    if (dataset != null)
                    {
                        dataset.Count         = music.Count;
                        dataset.Description   = music.Description;
                        dataset.MusicID       = music.MusicID;
                        dataset.InstrumentID  = music.InstrumentID;
                        dataset.CourseLevelID = music.CourseLevelID;

                        msg = "Notes Updated Successfully";
                    }
                }
                else
                {
                    entities.MusicSheets.Add(music);
                    msg = "New Notes Added successfully";
                }
                entities.SaveChanges();
                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        action = "Note",
                        message = msg
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }

            return(PartialView(music));
        }
Esempio n. 13
0
        public void PlayBGM(MusicEnum key)
        {
            MusicSheet sound = SheetManager.Instance.GetMusicSheet(key);

            AudioManager.Instance.PlayBGM(sound.Path, (MusicTransition)sound.MusTransition, sound.Duration, sound.Volume);
        }
 public MidiContext()
 {
     MusicSheet = new MusicSheet();
 }
Esempio n. 15
0
 public MusicPlayer(MusicSheet musicSheet, Harp harp, IPlayAlgorithm algorithm)
 {
     _musicSheet = musicSheet;
     _harp       = harp;
     _algorithm  = algorithm;
 }
Esempio n. 16
0
 public MusicPlayer(MusicSheet musicSheet, InstrumentType instrument, IPlayAlgorithm algorithm)
 {
     Worker = new Thread(() => algorithm.Play(instrument, musicSheet.MetronomeMark, musicSheet.Melody.ToArray()));
 }
        private static string SerializeMeter(MusicSheet musicSheet)
        {
            var beatsPerMeasure = musicSheet.MetronomeMark.BeatsPerMeasure;

            return($"{beatsPerMeasure.Nominator}/{beatsPerMeasure.Denominator}");
        }
 private static string SerializeTempo(MusicSheet musicSheet)
 {
     return(musicSheet.MetronomeMark.Metronome.ToString());
 }