shaderシンセ用の自作クラスを使ってみる。その1
shaderシンセ用の自作クラスを使って、shadertoyのmusic shaderを鳴らしてみる。
今回は Byte Beat をshaderでやってます。Byte Beatもdeepな世界ですよ。ほぼカンで勝負だ。みたいな世界だ。
glSynth.pyはここ
from glSynth import * shadertoy = ''' vec2 mainSound( float time ) { int t = int(time * 8000.0); t = (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1; return 0.8 * vec2(float(t & 0xff - 128) / 128.); } ''' class MainWindow(GLSynth): def __init__(self, parent=None): super().__init__() self.setVolume(0.8) def shaderScript(self): return shadertoy + ''' void main(){ gain = mainSound(iTime); } ''' def initializeWindow(self): audioLayout = QHLayoutWidget(); self.layout.addWidget(audioLayout) backwardButton = QPushButton(); audioLayout.addWidget(backwardButton) self.ctrlButton = QPushButton(); audioLayout.addWidget(self.ctrlButton) audioLayout.layout.setContentsMargins(0, 0, 0, 0) backwardButton.setIcon(self.style().standardIcon(QStyle.SP_MediaSkipBackward)) self.ctrlButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPause)) backwardButton.clicked.connect(self.backwardButton_clicked) self.ctrlButton.clicked.connect(self.ctrlButton_clicked) def ctrlButton_clicked(self): if self.timer.isActive(): self.timer.stop() self.ctrlButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) else: self.timer.start(10) self.ctrlButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPause)) def backwardButton_clicked(self): self.phase = 0 def keyPressEvent(self, e): if e.key() == Qt.Key_Escape: self.close() if __name__ == '__main__': import sys app = QApplication(sys.argv) main_window = MainWindow() main_window.show() sys.exit(app.exec_())