mainwindow.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:solar-sails 作者: metrasynth 项目源码 文件源码
def on_action_export_wav_triggered(self):
        path = self.loaded_path
        if path:
            with self.catcher.more:
                project = self.exportable_project()
                slug = project.name.lower().replace(' ', '-')
                timestamp = now().strftime('%Y%m%d%H%M%S')
                bpm = project.initial_bpm / (project.initial_tpl / 6)
                filename = '{}-{}-{}bpm-{}.wav'.format(path, slug, bpm, timestamp)
                freq = 44100
                size = freq
                channels = 2
                data_type = float32
                p = BufferedProcess(freq=freq, size=size, channels=channels, data_type=data_type)
                slot = Slot(project, process=p)
                length = slot.get_song_length_frames()
                output = np.zeros((length, 2), data_type)
                position = 0
                slot.play_from_beginning()
                dialog = QProgressDialog('Writing WAV to {}'.format(filename), 'Cancel', 0, length, self)
                dialog.setWindowModality(Qt.WindowModal)
                dialog.forceShow()
                cancelled = False
                while position < length:
                    if dialog.wasCanceled():
                        cancelled = True
                        break
                    buffer = p.fill_buffer()
                    end_pos = min(position + freq, length)
                    copy_size = end_pos - position
                    output[position:end_pos] = buffer[:copy_size]
                    position = end_pos
                    dialog.setValue(position)
                if not cancelled:
                    wavfile.write(filename, freq, output)
                    print('Exported project to {}'.format(filename))
                else:
                    print('Cancelled export')
                p.deinit()
                p.kill()
                dialog.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号