コード例 #1
0
def play_sound_start():
    sound = ps()
    try:
        while True:  #メインループ
            #keybord input!

            fin_tmp = int(input('ps >>'))
            if fin_tmp == 7777:
                del sound
                break
            fin_tmp -= 1
            if fin_tmp < 0 or fin_tmp > 8:
                fin_tmp = -1

            #data_input!
            '''
            f = open('./input_data.txt', 'r')
            lines = f.readlines()
            for l in lines:
                i_data = l.split(':')
                print(i_data[1])
                fin_tmp = sound.fingering_check(i_data[1].strip())
                print(fin_tmp)
                sound.sr_play(int(fin_tmp))
                time.sleep(0.1)
            '''

            #device input!
            #fin_tmp = int(ps.FingeringCheck(ifingering))
            sound.sr_play(fin_tmp)

            time.sleep(0.1)
    except KeyboardInterrupt:
        pass
コード例 #2
0
    def __init__(self, cv, root):
        self.damy_mode = 0 #演奏デバイスと通信せずに動かす
        self.center_adj = 100 #中央寄せ調整用
        self.draw_mag = 2.0 #フルスクリーン時、表示するディスプレイに合わせるため
        self.cv = cv
        self.root = root
        self.flag = 0
        self.button = gi()#PaspberryPiでの動作確認

        # 再帰回数の設定
        sys.setrecursionlimit(6000)

        # sound dataの読み込み_試験用
        self.sound_data = self.__read_file()

        # 受信の準備
        if not self.damy_mode:
            self.udp_data = uc()#PaspberryPiでの動作確認

        # 音を出す準備
        self.sound = ps()

        #記録をとる準備
        self.write_rec = o_re()
        self.write_rec_flag = 0
コード例 #3
0
    def __init__(self, music_name, cv, p_frame, mode_name):
        self.cv = cv
        self.root = p_frame
        self.music_name = music_name
        self.mode_name = mode_name
        #self.button = gi() #RaspberryPiでの動作確認

        self.music_deta = []
        self.last_time = time.time()
        self.first_roop = 1
        self.draw_point = 0
        self.seek_point = 5
        self.last_seek_point = 5  #入力描画用
        self.end_flag = 0
        self.bpm = 0
        self.measure = 0

        self.music_sound = ["ド", "レ", "ミ", "ファ", "ソ", "ラ", "シ", "ド", "レ"]
        self.labals_update = -1
        self.labels = []

        # 受信の準備 #RaspberryPiでの動作確認 and 演奏デバイスと通信時
        # self.udp_data = uc()#PaspberryPiでの動作確認

        # 音を出す準備
        self.sound = ps()
        self.rcv_data_s = []

        #記録をとる準備
        self.write_rec = o_re()

        self.chan_in = 0
        self.chan_in_point = 0
        self.score_update = 1

        self.d_input = di()  #PCでの動作確認

        if self.mode_name == "PLAY_RECORDING":
            l_music_data = rs.read_score(self.music_name)
            self.bpm = l_music_data[0]
            self.measure = l_music_data[1]
            del l_music_data[0:2]
            self.music_deta = l_music_data
            for i in self.music_deta:
                print(i)
        else:
            l_music_data = rs.read_score(self.music_name)  #, self.mode_name)
            self.bpm = l_music_data[0]
            self.measure = l_music_data[1]
            del l_music_data[0:2]
            self.music_deta = l_music_data
            for i in self.music_deta:
                print(i)
コード例 #4
0
    def __init__(self, cv, root):
        self.cv = cv
        self.root = root
        self.flag = 0
        #self.button = gi()#PaspberryPiでの動作確認

        # 再帰回数の設定
        sys.setrecursionlimit(6000)

        # sound dataの読み込み_試験用
        self.sound_data = self.__read_file()

        # 受信の準備
        # self.udp_data = uc()
        # 音を出す準備
        self.sound = ps()
コード例 #5
0
    def __init__(self, music_name, cv, p_frame, mode_name):
        self.damy_mode = 0  #演奏デバイスと通信せずに動かす
        self.center_adj = 100  #中央寄せ調整用
        self.draw_mag = 2.0  #フルスクリーン時、表示するディスプレイに合わせるため
        self.cv = cv
        self.root = p_frame
        self.music_name = music_name
        self.mode_name = mode_name
        self.button = gi()  #RaspberryPiでの動作確認

        self.music_deta = []
        self.last_time = time.time()
        self.last_input_time = time.time()
        self.start_time = time.time()
        self.first_roop = 1
        #self.draw_point = 0
        self.seek_point = 5
        self.last_seek_point = 5  #入力描画用
        self.end_flag = 0

        self.music_sound = ["ド", "レ", "ミ", "ファ", "ソ", "ラ", "シ", "ド", "レ"]
        self.labels = []

        self.m_p = [
            127.5, 122.5, 117.5, 112.5, 107.5, 102.5, 97.5, 92.5, 87.5
        ]  #音階の描画位置

        # 受信の準備 #RaspberryPiでの動作確認 and 演奏デバイスと通信時
        if not self.damy_mode:
            self.udp_data = uc()  #PaspberryPiでの動作確認

        # PCでの動作確認
        self.d_input = di()

        # 音を出す準備
        self.sound = ps()
        self.rcv_data_s = ['0', '00000000']

        #記録をとる準備
        self.write_rec = o_re()

        #お手本を読む
        if self.mode_name == 'JUDGE_PLAY':
            l_music_data = rs.read_score(self.music_name)
        else:
            l_music_data = rs.read_recording(self.music_name)
        noteLength = l_music_data[0]
        self.radix = l_music_data[1]
        self.bpm = 60 / noteLength
        del l_music_data[0:2]
        self.exa_music_datas = l_music_data
        self.exa_counter = 0

        #カタカナデータを読む
        self._read_scale_kana()
        self.kana_last_write = 0
        self.kana_num = 0
        self.drawing_kana = self.kana_lines[self.kana_num]  #.split(':')

        self.seek_limit = noteLength * self.radix * 2  #2小説の演奏にかかる時間7
        print('self.seek_limit : ', self.seek_limit)
        self.num_measure_data = self.seek_limit / 0.05  #二小説の描画に必要なデータ数
        print('self.num_measure_data : ', self.num_measure_data)
        #print('self.num_measure_data to int: ', int(self.num_measure_data))
        self.draw_min_size = 500 * self.draw_mag / self.num_measure_data

        #実験用
        self.input_counter = 0
        self.reflesh = 1

        #メトロノームの準備
        self.b_metro = bm(self.root, self.bpm)
コード例 #6
0
class DrawScore:
    '''
    music_deta = [  
        1,1,0,0,1,1,2,2,
        4,4,2,2,1,1,1,1,
        2,2,4,4,5,5,4,5,
        8,8,6,6,5,5,4,4,
        2,2,4,4,5,5,5,5,
        8,8,7,7,8,8,8,8,
        2,2,4,4,5,5,4,4,
        2,2,2,4,1,1,1,1,
        5,5,7,7,8,8,8,8,
        7,7,8,8,5,5,4,4,
        5,5,4,2,1,1,1,1
    ]
    '''
    music_deta = []
    #root = tk.Tk("1024x600")
    last_time = time.time()
    draw_point = 0
    seek_point = 10
    end_flag = 0
    bpm = 0
    measure = 0
    

    music_sound = ["ド","レ","ミ","ファ","ソ","ラ","シ","ド","レ"]
    labals_update = -1
    labels = []
    #cv = tk.Canvas(root,width = 1024,height = 600)
    sound = ps()

    def __init__(self, music_name,cv,p_frame,mode_name):
        self.cv = cv
        self.root = p_frame
        self.mode_name =mode_name
        #self.button = gi()
        #self.cv.pack()
        if self.mode_name == "PLAY_RECORDING":
            l_music_data = rs.read_score(music_name)
            self.bpm = l_music_data[0]
            self.measure = l_music_data[1]
            del l_music_data[0:2]
            self.music_deta = l_music_data
            for i in self.music_deta:
                print(i)
            self.root.after(10, self._draw_score_line)
            self.root.mainloop()

        else:
            l_music_data = rs.read_score(music_name)
            self.bpm = l_music_data[0]
            self.measure = l_music_data[1]
            del l_music_data[0:2]
            self.music_deta = l_music_data
            for i in self.music_deta:
                print(i)
            self.root.after(10, self._draw_score_line)
            self.root.mainloop()

    

    def _reset_labels(self):
        self.labals_update = 1
        for i in range(len(self.labels)):
            self.labels[i].place_forget()
        self.labels.clear()

    def _draw_score_line(self):
        '''
        if self.button.gpio_input() == 0:
            self.root.quit()
            return
        '''
        x = 0
        now_time = time.time()
        interval = now_time - self.last_time
        if interval >= self.bpm*self.measure*2:
            self.draw_point += 32*2#だと思う
            seek_point = 5#最も左のシーク位置
            self.last_time = time.time()
            if self.end_flag == 1:
                print("OKOKOKO")
                self.ans = j_s.judgement_score()
                print("ANS_e:", self.ans)
                self.label = tk.Label(self.root,text = "正答率" + str(round(self.ans,1)) + "%" ,background = "white",font = ("",20,"bold"))
                self.label.place(x = 300, y = 240)
                self.root.update()
                
                time.sleep(3)
                print("interval : " + str(interval))
                print("end of draw_score_line")
                #self.root.destroy()
                self.root.quit()
                return
            self._reset_labels()
        elif self.labals_update == -1:#要改良
            self._reset_labels()      
        else:
            self.labals_update = 0
        
        seek_point = 5.0+ 500.0*float(interval/(self.bpm*self.measure*2))
        self.last_seek = time.time()

        self.cv.delete("all")
        self.cv.create_polygon(0, 0, 512, 0, 512, 300, 0, 300, fill = "white")
        #五線譜の表示
        #五線譜の表示
        for i in range(0,5):
            i = i * 10
            self.cv.create_line(5,80+i,505,80+i)
        #小節毎の区切りの線
        self.cv.create_line(5,80,5,120)
        self.cv.create_line(255,80,255,120)
        self.cv.create_line(505,80,505,120)

        m_p = [127.5,122.5,117.5,112.5,107.5,102.5,97.5,92.5,87.5]#音階の描画位置
        count = 0
        old_m = -1
        old_change = 5
        for j in self.music_deta:#range(draw_point, draw_point + 16):
            if self.draw_point <= count and self.draw_point + 32*2 > count:
                if count > len(self.music_deta):
                    break
                #print(str(j) + ':' + str(draw_point))
                x1=x * 500/(32*2)#x1 = x * 62.5
                #self.cv.create_polygon(x1 + 10,M_s[j],72.5 + x1,M_s[j],72.5 + x1,M_s[j] + 10,x1 + 10,M_s[j] + 10 , tag ="polygon")
                self.cv.create_polygon(x1 + 5,m_p[j],5 + 500/(32*2) + x1,m_p[j],5 + 500/(32*2) + x1,m_p[j] + 5,x1 + 5,m_p[j] + 5 , tag ="polygon")

                #音階が変わったかを検知
                if count == self.draw_point:
                    old_m = j
                if self.labals_update == 1:
                    if j != old_m or count == self.draw_point + 32*2-1 or count == len(self.music_deta)-1:
                        self.labels.append(tk.Label(text = self.music_sound[old_m],background = "white",font = ("",10,"bold")))
                        self.labels[len(self.labels)-1].place(x = (old_change + x1 )/2 - 5,y = 150)
                        old_m = j
                        old_change = x1 + 5

                #cv.update()
                x = x + 1
                if x == 32*2:
                    x = 0
                    #cv.delete("polygon")
            if count >= self.draw_point + 32*2:
                break
            count += 1
    
        self.cv.create_polygon(seek_point-2, 50, seek_point+2, 50, seek_point + 2, 140, seek_point -2, 140, fill = "red")#シーク線
        if self.draw_point + 32*2 >= len(self.music_deta):
            #print("flag of draw_score_line")
            self.end_flag = 1
            
        
        self.root.after(10, self._draw_score_line)