Mercurial > hg > Game > Games
comparison Orchestland/Assets/Scripts/MusicPlayer.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 | |
4 public class MusicPlayer : MonoBehaviour { | |
5 public float bpm_default = 120f; | |
6 public int beat_change = 4; | |
7 public int beat_unit = 5; | |
8 public TempoCheck tempo_check; | |
9 | |
10 AudioSource source; | |
11 TimeStretch timeStretch; | |
12 float bpm_now; | |
13 int beat_count = -99; | |
14 int beat = 0; | |
15 float beat_f = 0f; | |
16 // Use this for initialization | |
17 void Start () { | |
18 source = GetComponent<AudioSource> (); | |
19 timeStretch = GetComponent<TimeStretch> (); | |
20 bpm_now = bpm_default; | |
21 } | |
22 | |
23 // Update is called once per frame | |
24 void Update () { | |
25 float time = source.time; | |
26 beat_f = time / (60f / bpm_default); | |
27 beat = Mathf.FloorToInt (beat_f); | |
28 if (beat_count != beat/beat_change) { | |
29 bpm_now = Mathf.Floor (tempo_check.GetTempoAverage ()/beat_unit)*beat_unit; | |
30 if (bpm_now > 80 && bpm_now < 200) { | |
31 timeStretch.speed = bpm_now / bpm_default; | |
32 } | |
33 | |
34 beat_count = beat/beat_change; | |
35 } | |
36 } | |
37 | |
38 public float GetBPM(){ | |
39 return bpm_now; | |
40 } | |
41 | |
42 public int GetBeat(){ | |
43 return beat; | |
44 } | |
45 public float GetBeatFloat(){ | |
46 return beat_f; | |
47 } | |
48 } |