File size: 3,447 Bytes
ed1cdd1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygame
import mido
from gtts import gTTS
from pygame.locals import MOUSEBUTTONDOWN, KEYDOWN, K_RETURN
import time

# Initialize the click count and the time of the last click
click_count = 0
last_click_time = 0

# Initialize Pygame and create a window for the MIDI editor
pygame.init()
screen = pygame.display.set_mode((640, 480))

class MidiNote:
    def __init__(self, note, velocity, time, x, y, width, height):
        self.note = note
        self.velocity = velocity
        self.time = time
        self.x = x
        self.y = y
        self.width = width
        self.height = height


# Create a new MIDI file
mid = mido.MidiFile()

# Create a new MIDI track
track = mido.MidiTrack()

# Add the MIDI track to the file
mid.tracks.append(track)

# Create a function to add lyrics to a specific MIDI note
def add_lyrics(note, lyrics):
    # Add the lyrics to the MIDI note
    note.text = lyrics
    # Update the MIDI file with the new lyrics
    mid.save("song.mid")

# Create a function to get the MIDI note that was clicked on
def get_clicked_note(pos):
    # Iterate through the MIDI notes in the file
    for track in mid.tracks:
        for note in track:
            if isinstance(note, mido.Message):
                # Check if the mouse position is within the bounds of the MIDI note
                if pos[0] > note.x and pos[0] < note.x + note.width:
                    if pos[1] > note.y and pos[1] < note.y + note.height:
                        return note
    return None

# Create a function to convert the lyrics from Japanese to speech
def speak_lyrics(lyrics):
    tts = gTTS(lyrics, lang='ja')
    tts.save('lyrics.mp3')
    pygame.mixer.music.load('lyrics.mp3')
    pygame.mixer.music.play()


# Main loop
while True:
    for event in pygame.event.get():
        if event.type == MOUSEBUTTONDOWN:
            # Increment the click count
            click_count += 1
            # Check if the user double-clicked on a MIDI note
            if time.time() - last_click_time < 0.5:
                # Get the MIDI note that was clicked on
                note = get_clicked_note(event.pos)
                # Add the lyrics to the MIDI note
                add_lyrics(note, lyrics)
                # Reset the click count
                click_count = 0
            # Update the time of the last click
            last_click_time = time.time()
        if event.type == KEYDOWN:
            if event.key == K_RETURN:
                # Get the lyrics from the input field
                lyrics = input_field.get_text()
                # Convert the lyrics to speech and play them
                speak_lyrics(lyrics)
    # If the click count is not reset, it means that the user has single-clicked
    if click_count == 1:
        # Get the position of the single click
        pos = pygame.mouse.get_pos()
        # Create a new MIDI note with the specified position and length
        note = MidiNote(60, 64, 0, event.pos[0], event.pos[1], 100, 100)
        note.x = pos[0]
        note.y = pos[1]
        note.width = 100
        note.height = 100
        # Add the MIDI note to the track
        track.append(note)
        mid.save("song.mid")
        # Reset the click count
        click_count = 0
    lyrics = ""

    input_field = pygame.font.Font(None, 32).render(lyrics, True, (0, 0, 0))

    # Display the input field on the window
    screen.blit(input_field, (10, 10))
    pygame.display.flip()